You stand on index 0 of nums. From index i you may jump forward any distance from 1 up to nums[i], so from a 0 you cannot move at all. Return true if some series of jumps ends on the last index, and false if none does.
Example 1
Input
nums = [3, 0, 2, 0, 1]
Output
true
Explanation
jump 2 steps from index 0 to index 2, then 2 steps from index 2 to index 4. The 0s at indexes 1 and 3 are never landed on.
Example 2
Input
nums = [2, 1, 0, 0, 3]
Output
false
Explanation
index 0 reaches index 1 or 2, and index 1 only reaches index 2. Index 2 holds 0, so you cannot get past it to index 3 or 4.
Example 3
Input
nums = [0]
Output
true
Explanation
you already stand on the last index, so no jump is needed.
Constraints:
1 <= nums.length <= 10^4
0 <= nums[i] <= 10^5
Tab indents. Press Esc, then Tab to leave the editor.
Ctrl or ⌘ + Enter runs the tests.
Run your code to see every test here. Nothing is submitted or recorded.