45. 跳跃游戏 II
class Solution {
public int jump(int[] nums) {
int len = nums.length;
int start = 0;
int end = 0;
int maxIndex = 0;
int count = 0;
//当end边界超出数组长度时跳出
while(end < len - 1){
for(int i = start; i <= end; i++){
//获取当前可达最大下标
maxIndex = Math.max(i + nums[i], maxIndex);
}
//下一轮遍历的起始位置
start = end + 1;
//下一轮遍历的结束位置
end = maxIndex;
//跳跃次数
count++;
}
return count;
}
}