Skip to content

Jump Game

01 · Question

You are given an integer array nums where nums[i] is your maximum jump length from index i. Return true if you can reach the last index.

02 · Solution

Reference solution

1def canJump(nums: List[int]) -> bool:
2 farthest = 0
3 for i, x in enumerate(nums):
4 if i > farthest:
5 return False
6 farthest = max(farthest, i + x)
7 return True