Java 6 lines O(n) no extra space AC solution


  • 2
    E
    public boolean canJump(int[] A) {
       
       if (A == null || A.length == 0) return false; 
       int maxF = A[0];
       
       for (int i = 0;i <= maxF && maxF < A.length - 1; i++){
           maxF =  i+ A[i] > maxF ?  i+A[i] : maxF;
       }
       
       return maxF >= A.length -1;
    }

Log in to reply
 

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