Share Java AC solution with O(n) running time

  • 3

    //jump: the distance it can jump from current position, as i increase ,it will decrease. When i reaches the //second number from the last ,jump still >0, it will return true.

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

Log in to reply

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