Simple solution in Python O(nlogn)


  • 0
    X
    class Solution(object):
        def insert(self, intervals, newInterval):
            """
            :type intervals: List[Interval]
            :type newInterval: Interval
            :rtype: List[Interval]
            """
            intervals.append(newInterval)
            res = []
            for i in sorted(intervals,key=lambda x: x.start):
                if res and i.start <= res[-1].end:
                    res[-1].end = max(res[-1].end, i.end)
                else:
                    res += i,
            return res

Log in to reply
 

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