A java solution with O(n) time and O(1) space


  • 0
    W

    public class Solution {
    public boolean canJump(int[] A) {
    int farest = 0;
    for(int i=0;i<A.length;i++){
    if(i>farest){
    break;
    }
    if(A[i]+i>farest){
    farest = A[i]+i;
    }
    }
    return farest>=A.length-1?true:false;
    }
    }


Log in to reply
 

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