```
class Solution {
public:
int eraseOverlapIntervals(vector<Interval>& intervals) {
sort(intervals.begin(), intervals.end(), [](const Interval& A, const Interval& B) { return A.start < B.start; });
int i = 0, res = 0, last;
while (i < intervals.size()) {
last = intervals[i++].end;
while (i < intervals.size() && intervals[i].start < last) {
++res;
last = min(last, intervals[i++].end);
}
}
return res;
}
};
```