Solution
- Always check if we can arrive at the next position,i.e.
curr >= idx
. - Keep the furthest position we can approach.
- If we can always approach the next position and the furthest approachable is further than the last position, then can jump.
def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ curr = 0 for idx, num in enumerate(nums): if curr < idx: return False reachable = num + idx curr = max(curr, reachable) return len(nums) - 1 <= curr
PREVIOUSUnique Paths
NEXTWord Break