8.10 *Greedy* JumpGame I&II

- to do

8.10 *Greedy* JumpGame I&II_第1张图片

12.1] Jump Game

    bool canJump(vector& nums) {
        int rightMost = 0;
        for (int i=0; i<=rightMost && i= nums.size()-1;
    }

stepping from top towards bottom

    bool canJump(vector& nums) {
        int leftMost = nums.size()-1;
        for (int i=nums.size()-2; i>=0; --i) {
            if (i+nums[i] >=leftMost)
                leftMost = i;
        }
        return leftMost==0;
    }

naive

    int jump(vector& nums) {
      if (nums.size()<2) return 0;
      vector minSteps(nums.size(), INT_MAX);
      int i=0; //inspect point
      minSteps[0] = 0;
      for (int j=i+1; j<=i+nums[0] && j

......................................

45. Jump Game II

    int jump(vector& nums) {
        int step=0, start=0, end=0; 
        int n=nums.size();
        while (end= n-1) return step;
                maxEnd = max(maxEnd, i+nums[i]);
            }
            start = end+1;
            end = maxEnd;
        }
        return step;
    }

你可能感兴趣的:(8.10 *Greedy* JumpGame I&II)