解题思路
请参考【LeetCode】45. 跳跃游戏 II python实现
python 代码
class Solution:
def canJump(self, nums: List[int]) -> bool:
start = 0
end = 1
n = len(nums)
step = 0
while end < n:
temp = 0
for i in range(start,end):
temp = max(temp,i + nums[i])
start = end
end = temp + 1
if start==end:
return False
step += 1
return True
s = Solution()
result = s.canJump([3,2,1,0,4])
print(result)