标签:lang code ++ inf tin mamicode com lan png
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals)
{
sort(intervals.begin(), intervals.end(), [](const vector<int> &pl1, const vector<int> &pl2) {
return pl1[0] < pl2[0];
});
int cur = 0, len = intervals.size();
for (int i = 1; i < len; i++)
{
if (intervals[cur][1] < intervals[i][0])
{
cur++;
intervals[cur][0] = intervals[i][0];
}
else if(intervals[cur][1] >= intervals[i][1])
continue;
intervals[cur][1] = intervals[i][1];
}
auto itor = intervals.begin() + cur;
if(itor != intervals.end())
intervals.erase(itor + 1, intervals.end());
return intervals;
}
};
标签:lang code ++ inf tin mamicode com lan png
原文地址:https://www.cnblogs.com/woodjay/p/12716885.html