这道题自己实在没思路,然后看到别人写的,自己还是太弱了,fighting
public class ImportantJumpGame {
public boolean canJump(int[] nums) {
if(nums.length == 0 || nums.length == 1){
return true;
}
int maxStep = nums[0];
for(int i = 1;i < nums.length;i ++){
//每次先判断可前进的最大步数,为0,则不能移动
if(maxStep == 0){
return false;
}
maxStep --;
if(nums[i] > maxStep){
maxStep = nums[i];
}
if(maxStep + i >= nums.length - 1){
return true;
}
}
return true;
}
}