Share my java solution


  • 0
    S

    Think that if the second to last can jump to the last,we just need to consider can we jump to the second to last.And so on.
    public boolean canJump(int[] nums) {
    int n=nums.length;
    if(n==1) return true;
    int start=n-2;
    int loc=n-1;
    while(start>=0){
    if(nums[start]<(loc-start)){
    start-=1;
    }else {
    loc=start;
    start=loc-1;

            }
    
        }
    return loc==0?true:false;
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.