Accepted Python Solution

  • 0
    class Solution:
        # @param intervals, a list of Interval
        # @return a list of Interval
        def merge(self, intervals):
            if not intervals:
                return []
            intervals.sort(key=lambda x: x.start)
            result = [intervals[0]]
            for i in range(1,len(intervals)):
                if result[-1].end >= intervals[i].start:
                    result[-1].end = max(intervals[i].end,result[-1].end )
            return result

Log in to reply

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