leetcode

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

1024.cpp (503B)


      1 class Solution {
      2   public:
      3     int videoStitching(vector<vector<int>> &clips, const int time) const {
      4         const int n = size(clips);
      5         int res = 0, start = 0, finish = 0;
      6 
      7         sort(begin(clips), end(clips));
      8         for (int i = 0; start < time; res++) {
      9             for (; i < n && clips[i][0] <= start; i++) {
     10                 finish = max(finish, clips[i][1]);
     11             }
     12             if (start == finish) return -1;
     13             start = finish;
     14         }
     15 
     16         return res;
     17     }
     18 };