Concise python code, easy understanding


  • 2
    H
    class Solution(object):
        def merge(self, intervals):
            """
            :type intervals: List[Interval]
            :rtype: List[Interval]
            """
            intervals = sorted(intervals, key=lambda interval:interval.start)
            result = []
            interval, l = intervals[0], len(intervals)
            for i in range(1, l):
                interval2 = intervals[i]
                if interval2.start > interval.end:
                    result.append(interval)
                    interval = interval2
                else:
                    interval.end = max(interval.end, interval2.end)
            
            result.append(interval)
            return result

Log in to reply
 

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