A different approach...c++.o(n)


  • 0
    N
    class Solution {
    public:
        bool canJump(vector<int>& nums) {
            if(nums.size()==0||nums.size()==1)return true;
            int i=nums.size()-2,j=1;
            while(i!=0)
            {
                if(nums[i]<j)
                {
                    j++;
                }
                else j=1;
                i--;
            }
            if(nums[i]<j)return false;
            return true;
        }
    };

Log in to reply
 

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