Участник:D.feldman/non-overlapping-intervals

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/non-overlapping-intervals/

class Solution:
    def eraseOverlapIntervals(self, intervals: List[List[int]]):
 
        intervals = sorted((x[1], x[0]) for x in intervals)
 
        deleted = 0
        e = -1e123
 
        for interval in intervals:
            if interval[1] >= e:
                 deleted += 1
 
                 e = interval[0]
 
        return len(intervals) - deleted