题目
Given an array of non-negative integers, you are initially positioned at the first index of the array.
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.
For example:
Given array A = [2,3,1,1,4]
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.)
翻译一下 是jump gamehttp://blog.youkuaiyun.com/zl87758539/article/details/51694895那个题目派生出来的。
之前那个是问你能不能跳到最后一个,现在是给你一个数组,肯定能跳到最后,问你最少需要多少步。
其实思路差不多的,之前用贪心,比如说n个数,第i个数跳的最远记下来, G=max(G,nums[i]+i)
现在肯定也要记,只不过是,记每一步跳的最远,我们设一个 Gstep 也可以简称 G