My Python solution


  • 0
    R
    class Solution(object):
        def insert(self, intervals, newInterval):
            """
            :type intervals: List[Interval]
            :type newInterval: Interval
            :rtype: List[Interval]
            """
            left = list()
            right = list()
            newList = list()
            for interval in intervals:
                if interval.end < newInterval.start:
                    left.append(interval)
                elif interval.start > newInterval.end:
                    right.append(interval)
                else:
                    if interval.start < newInterval.start:
                        newInterval.start = interval.start
                    if interval.end > newInterval.end:
                        newInterval.end = interval.end
            newList.append(newInterval)
            return left + newList + right
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.