【LeetCode 55. Jump Game 时间复杂度(O(n))】 时间复杂度(O(n)),思想:动态规划
class Solution:
def canJump(self, nums: [int]) -> bool:
nums_len = len(nums)
if nums[0] == 0 and nums_len > 1: return False
path_status = [False] * nums_len
path_status[0] = True
path_index = 0
path_count = 1
for index, num in enumerate(nums):
while path_index <= index + num:
if path_index <= index: path_index = path_index + 1
if path_index >= nums_len: break
path_status[path_index] = True
path_index += 1
path_count += 1
return path_count == nums_len
推荐阅读
- LeetCode 45. Jump Game II 时间复杂度(O(n))
- LeetCode|LeetCode 42. Trapping Rain Water 时间复杂度(O(n))
- leetcode|算法入门之字符串(Python)【初级算法——字符串】【蓝桥杯练习】【力扣练习】
- Python|【蓝桥杯真题】Python备战28天
- #|LeetCode344. 反转字符串
- 算法|LeetCode Golang Hot53-最大子数组和
- leetcode|leetcode 344.反转字符串(reverse string)C语言
- LeetCode 668. 乘法表中第k小的数
- 算法题-字符串3.17