Simple and easy to understand C++ solution, O(n) time complexity, O(1) space complexity.


  • 1
    A
    class Solution {
    public:
        bool canJump(int A[], int n) {
            int i,end=n-1;
            
            for(i=n-2;i>=0;i--)
            {
                if(A[i]>=(end-i))
                {
                    end = i;
                }
            }
            if(end<=0)
            return true;
            else
            return false;
            
        }
    };

Log in to reply
 

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