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)


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