用maxstep记录最大步程,然后遍历(greedy)
1 public class Solution { 2 public boolean canJump(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int maxstep = 0; 6 for(int i = 0; i < A.length; i++) 7 { 8 if(i > maxstep) 9 return false; 10 maxstep = Math.max(maxstep, (i + A[i])); 11 if(maxstep >= A.length - 1) 12 return true; 13 } 14 return true; 15 } 16 17 }