Python solution beats 95%


  • 0
    D
     class Solution(object):
        def merge(self, intervals):
            """
            :type intervals: List[Interval]
            :rtype: List[Interval]
            """
            res = []
            if not intervals: return res
            intervals.sort(key=lambda i:i.start)
            curr = intervals[0]
        
            for i in intervals:
                if i.start<=curr.end:
                    curr.end = max(curr.end,i.end)
                else:
                    res.append(curr)
                    curr = i
            res.append(curr)
            return res

Log in to reply
 

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