My solution with O(n) time

  • 0
    bool canJump(int A[], int n) {
        if(n<=1)return true;
        int Z=1;
        for(int i=n-2;i>=0;i--)
            if(A[i]==0||A[i]<Z) Z++;
            else Z=1;
        if(Z==1) return true;
        else return false;

    "Z" is to identify the steps needed at least to jump over "0".

Log in to reply

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