Jump Game II
class Solution {
public int jump(int[] nums) {
int n = nums.length, step = 0, last = 0, max = 0;
for(int i = 0; i < n - 1, i ++){//只到n-1 到最后一步不要step++了
max = Math.max(max, i + nums[i]);
if(i == last){
last = max;
step ++;
}
}
return step;
}
}Last updated