1 class Solution: 2 def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]: 3 n = len(intervals) 4 res = [] 5 for i in range(n): 6 curent = intervals[i] 7 if curent[1] <= toBeRemoved[0] or curent[0] >= toBeRemoved[1]: 8 res.append(curent) 9 elif curent[0] >= toBeRemoved[0] and curent[1] <= toBeRemoved[1]: 10 continue 11 elif curent[0] <= toBeRemoved[0] and curent[1] >= toBeRemoved[1]: 12 if curent[0] != toBeRemoved[0]: 13 res.append([curent[0],toBeRemoved[0]]) 14 if toBeRemoved[1] != curent[1]: 15 res.append([toBeRemoved[1],curent[1]]) 16 elif curent[0] <= toBeRemoved[0] and curent[1] >= toBeRemoved[0] and curent[1] <= toBeRemoved[1]: 17 if curent[0] != toBeRemoved[0]: 18 res.append([curent[0],toBeRemoved[0]]) 19 elif curent[1] >= toBeRemoved[1] and curent[0] <= toBeRemoved[1] and curent[0] >= toBeRemoved[0]: 20 if toBeRemoved[1] != curent[1]: 21 res.append([toBeRemoved[1],curent[1]]) 22 return res
分6种情况讨论(第一个if语句是两种情况)