-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path56.cpp
More file actions
25 lines (25 loc) · 685 Bytes
/
56.cpp
File metadata and controls
25 lines (25 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals) {
if(intervals.empty())
return {};
sort(intervals.begin(),intervals.end());
vector<vector<int>> res;
int i = 0;
res.push_back(intervals[i]);
int j = 1;
int n = intervals.size();
while(j<n){
if(res[i][1]>= intervals[j][0]){
res[i][0] = min(intervals[j][0],res[i][0]);
res[i][1] = max(intervals[j][1],res[i][1]);
}
else{
res.push_back(intervals[j]);
i++;
}
j++;
}
return res;
}
};