public class Solution {
public boolean canJump(int[] A) {
// Start typing your Java solution below
// DO NOT write main() function
if(A==null||A.length==1)return true;
int len = A.length;
int max = A[0];
for(int i = 0; i < len-1;i++){
if(A[i]==0&&max==i)return false;
max = Math.max(max,i+A[i]);
}
if(max>=len-1)return true;
else return false;
}
}
Jump Game
最新推荐文章于 2021-03-16 19:38:59 发布