```
int eraseOverlapIntervals(vector<Interval>& intervals) {
sort(intervals.begin(), intervals.end(), [] (Interval i, Interval j) {return i.end < j.end;});
int res = 0, temp = INT_MIN;
for (auto i : intervals) {
if (temp > i.start) res++;
else if (i.end > temp) temp = i.end;
}
return res;
}
```