← 返回 amazon 的题目列表Minimum Jumps to Reach Array End
类型:online_judge
amazon
Given a non-negative integer array, you are initially positioned at the array's first index. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps. Write a function to compute the minimum number of jumps needed.
Input
A non-negative integer array nums, with 1 <= nums.length <= 1000 and 0 <= nums[i] <= 100.
Output
The minimum number of jumps to reach the last index.
Example
Input:
[2,3,1,1,4]
Output:
2
Explanation: Jump from index 0 to index 1, then to the last index, total 2 jumps.
Constraints
1 <= nums.length <= 1000
0 <= nums[i] <= 100
Example
Input
1
2 3 1 1 4