leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0045.cpp (397B)


      1 class Solution {
      2   public:
      3     int jump(vector<int> &nums) {
      4         int n = nums.size(), limit = 0;
      5         vector<int> num(n);
      6         num[0] = 0;
      7         for (int i = 0; i <= limit && i < n; i++) {
      8             for (int j = limit + 1; j <= i + nums[i] && j < n; j++)
      9                 num[j] = num[i] + 1;
     10             limit = max(limit, i + nums[i]);
     11         }
     12         return num.back();
     13     }
     14 };