51. Jump Game
MediumGreedy
Given an integer array `nums`, where each element represents the maximum jump length from that position, determine if you can reach the last index starting from index 0. For example, given nums = [2,3,1,1,4], you can jump from index 0 to index 1 (jump 1 step), then from index 1 to the last index (jump 3 steps), so the answer is true. Given nums = [3,2,1,0,4], no matter what you do, you will always arrive at index 3 whose value is 0, so you can never reach the last index.
Examples
Input: [2,3,1,1,4]
Output: true
Explanation: Jump 1 step from index 0 to 1, then 3 steps to the last index.
Constraints
- 1 <= nums.length <= 10^4
- 0 <= nums[i] <= 10^5
Loading...
Run checks all cases above. Submit evaluates all test cases.