#45
Jump Game II
specialist · 975 · lc medium +32 · verified · 42.5% accepted · 16,399 likes · top 24%
Description
Starting at index 0 of the 0-indexed array nums, where nums[i] is the maximum forward jump length from index i, return the minimum number of jumps to reach the last index. It is guaranteed a valid path always exists.
Example 1:
Input: nums = [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
Example 2:
Input: nums = [2,3,0,1,4]
Output: 2
Code
1
2
3