
class Solution {
public:
static bool cmp(vector<int> &a, vector<int> &b){
// if(a[0]!=b[0])
return a[0]<b[0];
// else
// return a[1]<b[1];
}
vector<vector<int>> merge(vector<vector<int>>& intervals) {
vector<vector<int>> res;
sort(intervals.begin(), intervals.end(),cmp);
vector<int> temp;
temp.push_back(intervals[0][0]);
temp.push_back(intervals[0][1]);
for(int j = 1; j < intervals.size(); j++){
if(intervals[j][0]<=temp[1]){ // 可以加入区间
if(intervals[j][1]>temp[1]) // 如果当前元素右边界大于当前区间的右边界
temp[1] = intervals[j][1]; // 更新右边界
}else{
res.push_back(temp);
temp[0] = intervals[j][0];
temp[1] = intervals[j][1];
}
}
res.push_back(temp);
return res;
}
};