题目链接:
LeetCode 55 — Jump Game
AC代码:
public class Problem55 {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public boolean canJump(int[] nums) {
if(nums.length<=1)
return true;
int now=0;
while(true){
if(now+nums[now]>=nums.length-1) return true;
if(nums[now]==0) return false;
now=judgegood(nums, now);
}
}
public int judgegood(int[] nums,int start){
int n = nums[start];
int max=0,p=start;
for(int i=1;i<=n;i++){
if(nums[start+i]+i>max){
max=nums[start+i]+i;
p=start+i;
}
}
return p;
}
}