Simple O(n) and O(1) Solution c++


  • 0
    A
     Find the maximum reach at every point
    
        bool canJump(vector<int>& nums) {
        int maxReach = 0;
        for(int i=0;i<nums.size();i++){
            if(i<=maxReach)
                maxReach = max(maxReach,i+nums[i]);            
            else
                return false;
        }
        return true;

Log in to reply
 

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