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