16 ms c++ solution


  • 0
    I
    int jump(vector<int>& nums) {
        int curstep = 0, curpos =0, nextpos =0, n = nums.size();
        if(n<=1) return 0;
        for (int i = 0; i<n; ++i)
        {
            if (i>curpos)
            {
                ++curstep;
                curpos = nextpos;
            }
            nextpos = max(nextpos, i+nums[i]);
            if (nextpos >=n-1) return curstep +1;
        }

Log in to reply
 

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