45. Jump Game II

PHOTO EMBED

Thu Feb 23 2023 11:21:41 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

class Solution {
public:
    int jump(vector<int>& nums) {
        int n=nums.size();
        int cr=0, cmx=0, j=0;
        for(int i=0;i<n-1;i++)
        {
            if(i+nums[i]>cmx) cmx=i+nums[i];
            
            if(i==cr)
            {
                j++;
                cr=cmx;
            }
        }
        return j;
    }
};
content_copyCOPY

https://leetcode.com/problems/jump-game-ii/