Somehow this python beats 93%


  • 1
    D
        n = len(intervals)
        if n == 0:
            return []
        L=[]
        d={}
        for i in range(n):
            if intervals[i].start in d:
                if intervals[i].end >= d[intervals[i].start].end:
                    d[intervals[i].start] = intervals[i]
            else:
                d[intervals[i].start] = intervals[i]
                L.append(intervals[i].start)
        L = sorted(L)
        A = []
        A.append(d[L[0]])
        for i in range(1,len(L)):
            if d[L[i]].start <= A[-1].end:
                a = min(d[L[i]].start,A[-1].start)
                b = max(d[L[i]].end,A[-1].end)
                inn = Interval(a,b)
                A[-1] = inn
            else:
                A.append(d[L[i]])
        return A

  • 0
    K

    Thanks for sharing ! very ingenious solution !


Log in to reply
 

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