package leetcode; public class demo_55 { public boolean canJump(int[] nums) { int end=nums.length-1; boolean flag=true; while(end>0) { int length=0; flag=false; //记录每一次能到达右边界最远的点 for(int i=end-1;i>=0;i--) { if(nums[i]+i>=end) { length=i; flag=true; } } end=length; //只要有一次无法达到右边界就说明无法到达 if(flag==false) {break;} } System.out.println(flag); return flag; } public static void main(String[] args) { // TODO Auto-generated method stub demo_55 d55=new demo_55(); int nums[]= {3,2,1,0,4}; d55.canJump(nums); } }