Very simple and intuitive code O(n) :D


  • 0
    N
    class Solution {
    public:
        int jump(vector<int>& nums) {
            int n = nums.size();
            int maxm = nums[0];
            int cnt = 0;
            for(int i=0;i<n-1;){
                cnt++;
                int p = maxm;
                for(int j=i;j<=p and j<n;j++){
                    maxm = max(maxm,j+nums[j]);
                }
                i = p;
            }
            return cnt;
        }
    };
    

Log in to reply
 

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