class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals) {
sort(intervals.begin(),intervals.end(),[](vector<int>& a,vector<int>& b){return a[0]<b[0];});
vector<vector<int>> ans;
for(auto& val:intervals){
if(ans.empty()||val[0]>ans.back()[1]){
ans.push_back(val);
}
else{
int t0=ans.back()[0];
int t1=ans.back()[1];
ans.pop_back();
ans.push_back({t0,max(val[1],t1)});
}
}
return ans;
}
};
c++匿名函数
最新推荐文章于 2023-06-16 21:34:35 发布