Share my concise 7-line python greedy algorithm


  • 0
    R
    class Solution(object):
        def eraseOverlapIntervals(self, intervals):
            intervals.sort(key=lambda x: x.end)
            count = 0
            for i in range(1, len(intervals)):
                if intervals[i].start<intervals[i-1].end:
                    count += 1
                    intervals[i] = intervals[i-1]
            return count
    

Log in to reply
 

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