class Solution {
public boolean canJump(int[] nums) {
return isend(nums,0);
}
/**
* 检查数组越界
*/
static boolean isend(int[] ints ,int index){
if(index>=ints.length-1){
return true;
}
//越界
if((ints[index]+index)>=ints.length-1){
return true;
}
int max = 0;
int dex =0;
for (int i = index+1; i <=index+ints[index] ; i++) {
if(i+ints[i]>max){
max = i+ints[i];
dex = i;
}
}
if(max<=index+ints[index]){
return false;
}
return isend(ints,dex);
}
}
LeetCode刷题55跳跃游戏 I
最新推荐文章于 2024-03-02 21:22:13 发布