-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path310.cpp
More file actions
26 lines (25 loc) · 700 Bytes
/
Copy path310.cpp
File metadata and controls
26 lines (25 loc) · 700 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
26
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals) {
int n=intervals.size(),i;
sort(intervals.begin(),intervals.end());
vector<vector<int>> ans;
int start=intervals[0][0];
int end=intervals[0][1];
for(i=1;i<n;i++)
{
if(intervals[i][0]<=end)
{
end=max(end,intervals[i][1]);
}
else
{
ans.push_back({start,end});
start=intervals[i][0];
end=intervals[i][1];
}
}
ans.push_back({start,end});
return ans;
}
};