leetcode

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

0435.cpp (508B)


      1 class Solution {
      2     typedef vector<int> interval;
      3 
      4   public:
      5     int eraseOverlapIntervals(vector<interval> &intervals) {
      6         auto cmp = [](const interval &i1, const interval &i2) { return i1[1] < i2[1]; };
      7         sort(intervals.begin(), intervals.end(), cmp);
      8 
      9         int end = intervals[0][1], count = 1;
     10         for (auto &i : intervals) {
     11             if (i[0] >= end) {
     12                 end = i[1];
     13                 count++;
     14             }
     15         }
     16         return intervals.size() - count;
     17     }
     18 };