class Solution {
public int jump(int[] nums) {
if (nums.length <= 1) return 0;
//记录每次起跳所能跳到的最远的距离
int farestIndex = 0;
int maxIndex = 0;
int start = 0;
int times = 0;
while(true){
for (int i = start; i <= farestIndex; i++){
if (maxIndex < (i + nums[i])){
maxIndex = i + nums[i];//记录当前条约范围内,能够调到最远距离的下标
}
}
times++;
start = farestIndex;
farestIndex = maxIndex;
maxIndex = 0;
if (farestIndex >= nums.length - 1) break;
}
return times;
}
}
标签:十一,150,int,nums,面试,length
From: https://www.cnblogs.com/poteitoutou/p/18008565