Skip to content

Commit 2be9731

Browse files
authored
Create remove-interval.cpp
1 parent 321113c commit 2be9731

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

C++/remove-interval.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
vector<vector<int>> removeInterval(vector<vector<int>>& intervals, vector<int>& toBeRemoved) {
7+
vector<vector<int>> result;
8+
for (const auto& interval : intervals) {
9+
vector<pair<int, int>> tmp = {{interval[0], min(toBeRemoved[0], interval[1])},
10+
{max(interval[0], toBeRemoved[1]), interval[1]}};
11+
for (const auto& [x, y] : tmp) {
12+
if (x < y) {
13+
result.push_back({x, y});
14+
}
15+
}
16+
}
17+
return result;
18+
}
19+
};

0 commit comments

Comments
 (0)