贪心
按照有边界排序,只有先选择了右边边界小的,才可以放下更多的区间
class Solution {
public:
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
if(intervals.empty())
return 0;
int n = intervals.size();
sort(intervals.begin(),intervals.end(),[](vector<int>&a,vector<int>&b){
return a[1]<b[1];
});
int total = 0,prev = intervals[0][1];
for(int i=1;i<n;i++){
if(intervals[i][0]<prev)
total++;
else
prev = intervals[i][1];
}
return total;
}
};
标签:Non,vector,return,Intervals,int,intervals,435,LeetCode
From: https://www.cnblogs.com/poteitoutou/p/16870907.html