Sharing my 16ms C++ solution


  • 0
    T
    class Solution {
    public:
        bool canJump(vector<int>& nums) {
            int pos = 0;
            int limit = nums[0];
            int n = nums.size();
            while(pos<limit && pos<n)
            {
                pos++;
                if(pos<n && pos+nums[pos]>limit)
                    limit = pos+nums[pos];
            }
            
            return (pos>=n-1);
        }
    };

Log in to reply
 

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