class Solution(object): def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ jump, length = 0, len(nums) for pos in range(length): # are you beyond your max range ? if pos > jump: return False # compute max range jump = max(jump, pos+nums[pos]) # are you beyond the array ? if jump >= length-1: return True return False
python - array jump
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.