Jump Game
You start on the first square of a row. Standing on square i, you may jump forward by any distance from 1 up to nums[i] (0 means you can't move from there). Return true if you can reach the last square, and false otherwise.
Constraints
- 1 ≤ length of
nums≤ 100,000 - 0 ≤
nums[i]≤ 100,000
Example 1
Input
nums = [2,3,1,1,4]
Output
true
Why:
Jump 1 to square 1, then 3 to the last square.
Example 2
Input
nums = [3,2,1,0,4]
Output
false
Why:
Every route lands on square 3, whose 0 stops you.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –