Sharing my 16ms C++ solution


  • 0
    T
    class Solution {
    public:
        int jump(vector<int>& nums) {
            int start=0, end=0, limit=0;
            int count=0;
            int n = nums.size();
            while(end<n-1)
            {
                count++;
                for(int i=start; i<=end; i++)
                    limit = max(limit, i+nums[i]);
                    
                start = end+1;
                end = limit;
            }
            
            return count;
        }
    };

Log in to reply
 

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