class Solution(object):
# 思路:
# 维护一个reach变量,代码能走到的最远index
# while循环, i <= reach,
# 每次更新reach
def canJump(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
reach = 0
i = 0
while i <= reach:
reach = max(reach, i+nums[i])
if reach >= len(nums) - 1:
return True
i += 1
return False
网友评论