描述
给出一个非负整数数组,你最初定位在数组的第一个位置。数组中的每个元素代表你在那个位置可以跳跃的最大长度。判断你是否能到达数组的最后一个位置。
样例
A = [2,3,1,1,4],返回 true.
A = [3,2,1,0,4],返回 false.
动态规划实现:
public class Solution {
public boolean canJump(int[] A) {
if(A==null || A.length<2) return true;
boolean[] can=new boolean[A.length];
can[0]=true;
for(int i=0; i<A.length; i++){
for(int j=i; j<=i+A[i] && j<A.length; j++){
if(can[i]){
can[j]=true;
}
}
}
return can[A.length-1];
}
}