Accepted Python Solution


  • 0
    J
    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 )
                else:
                    result.append(intervals[i])
            return result

Log in to reply
 

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