class Solution {
public int jump(int[] nums) {
int ans = 0;
int curIndex = 0;//当前统计出来的可以移动的最远距离的下标
int nextIndex = 0;//在到达 当前最远距离下标的这段距离内 我们统计出的可以达到的最远距离
//如果在统计的过程中 其覆盖范围已经大于数组下标了,那么我们就选择
//return ans+1;
for (int i = 0; i < nums.length; i++) {
nextIndex = Math.max(nextIndex,i+nums[i]);//i+nums[i] 从0开始可以移动最远的距离
if (nextIndex >= nums.length-1) return ans+1;
if (i == curIndex) {//当我们移动到
ans++;
curIndex = nextIndex;
}
}
return ans;
}
}



