Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 510 Bytes

File metadata and controls

25 lines (22 loc) · 510 Bytes

Solution

Code

class Solution {
public:
    int jump(vector<int>& nums)
    {
        int n = nums.size();
        int i = 0, j = 0, reachablePlace = 0, jumps = 0;
        while (j < n - 1) {
            reachablePlace = max(reachablePlace, i + nums[i]);
            if (i == j) {
                j = reachablePlace;
                jumps++;
            }
            i++;
        }
        return jumps;
    }
};