# 1272. Remove Interval
Given a sorted list of disjoint intervals, each interval intervals[i] = [a, b] represents the set of real numbers x such that a <= x < b.
We remove the intersections between any interval in intervals and the interval toBeRemoved.
Return a sorted list of intervals after all such removals.
Example 1:
Input: intervals = [[0,2],[3,4],[5,7]], toBeRemoved = [1,6]
Output: [[0,1],[6,7]]
Example 2:
Input: intervals = [[0,5]], toBeRemoved = [2,3]
Output: [[0,2],[3,5]]
# Solution
Approach 1: go through the list.
# Code (Python)
Approach 1:
class Solution:
def removeInterval(self, intervals: List[List[int]], removed: List[int]) -> List[List[int]]:
result = []
for interval in intervals:
if removed[0] >= interval[1] or removed[1] <= interval[0]:
result.append(interval)
else:
if interval[0] < removed[0]:
result.append([interval[0], removed[0]])
if interval[1] > removed[1]:
result.append([removed[1], interval[1]])
return result
# Code (C++)
Approach 1:
Approach 2: