Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 929 Bytes

1272. Remove Interval.md

File metadata and controls

29 lines (24 loc) · 929 Bytes

1272. Remove Interval

  • for each intervals 3 cases:
    • not overlapping, just add the interval to list.
    • if overlapping left, add left part (interval1[0], interval2[0])
    • if overlapping right, add right. (interval2[1], interval1[1])
class Solution(object):
    def removeInterval(self, intervals, toBeRemoved):
        """
        :type intervals: List[List[int]]
        :type toBeRemoved: List[int]
        :rtype: List[List[int]]
        """
        ans = []
        for oneInterval in intervals:
            if oneInterval[0] >= toBeRemoved[1] or oneInterval[1] <= toBeRemoved[0]:
                ans.append(oneInterval)
            else:
                if oneInterval[0] < toBeRemoved[0]:
                    ans.append((oneInterval[0], toBeRemoved[0]))
                if oneInterval[1] > toBeRemoved[1]:
                    ans.append((toBeRemoved[1], oneInterval[1]))
        return ans