跟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;
}
};