给出一个非负整数数组,你最初定位在数组的第一个位置。
数组中的每个元素代表你在那个位置可以跳跃的最大长度。
判断你是否能到达数组的最后一个位置。
样例
A = [2,3,1,1,4],返回 true.
A = [3,2,1,0,4],返回 false.
//二指针问题,最大覆盖区间。
public class Solution {
/**
* @param A: A list of integers
* @return: The boolean answer
*/
public boolean canJump(int[] A) {
// wirte your code here
int start=0,end=A[0];
for(int i=1;i<A.length;i++){
if(i+1<=end){
end=A[i]+i>end?A[i]+i:end;
}
if(end>=A.length){
return true;
}
}
return false;
}
}