forked from Viv786ek/100-daysofcodewithGFG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay-27
24 lines (23 loc) · 722 Bytes
/
Day-27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<vector<int>> overlappedInterval(vector<vector<int>>& intervals) {
// Code here
vector<vector<int>> mergedIntervals;
if(intervals.size()==0)
return mergedIntervals;
sort(intervals.begin(), intervals.end());
vector<int> tempInterval = intervals[0];
for(auto it: intervals )
{
if(it[0] <= tempInterval[1])
tempInterval[1] = max(it[1], tempInterval[1]);
else
{
mergedIntervals.push_back(tempInterval);
tempInterval = it;
}
}
mergedIntervals.push_back(tempInterval);
return mergedIntervals;
}
};