435. 无重叠区间
按照起点排序
若出现重叠,就将当前的终点取为当前终点和上一终点的最小值
intervals[i][1] = min(intervals[i-1][1],intervals[i][1]);
若没出现重叠,
class Solution {
public:
static bool cmp(vector<int>& a,vector<int>& b)
{
if(a[0]==b[0])return a[1]<b[1];
return a[0]<b[0];
}
int eraseOverlapIntervals(vector<vector<int>>& intervals) {
sort(intervals.begin(),intervals.end(),cmp);
int num = 0;
for(int i=1;i<intervals.size();i++)
{
if(intervals[i][0]<intervals[i-1][1])
{
intervals[i][1] = min(intervals[i-1][1],intervals[i][1]);
intervals[i][0]=intervals[i-1][0];
num++;
}
}
return num;
}
};