Leetcode第1288题 删除被覆盖区间C++解法
作者:互联网
跟435题一样,都是先排序。
class Solution {
public:
int removeCoveredIntervals(vector<vector<int>>& intervals) {
int size=intervals.size();
if(size<2) return 0;
sort(intervals.begin(),intervals.end(),[] (const auto& u,const auto& v){
if(u[0]==v[0])
return u[1]>v[1];
else
return u[0]<v[0];
});
auto it=intervals.begin();
int res=0,second=(*it)[1];
for(++it;it!=intervals.end();++it)
{
if(second>=(*it)[1])
++res;
else
second=(*it)[1];
}
return size-res;
}
};
标签:return,int,res,1288,C++,second,intervals,Leetcode,size 来源: https://blog.csdn.net/meixingshi/article/details/113851556