Python Clean Solution


  • 0
    D
    intervals.sort(key = lambda x: x.start)
            remove = 0
            i = 0
            n = len(intervals)
            last_end = -float('inf')
            while i < n:
                while i < n and intervals[i].start >= last_end: 
                    last_end = intervals[i].end
                    i += 1
                if i == n: return remove
                if intervals[i].end < last_end: 
                    last_end = intervals[i].end
                remove += 1
                i += 1
            return remove

Log in to reply
 

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