Python Solution -- 58ms(beats 97.12%)


  • 0
    K
    # Definition for an interval.
    # class Interval(object):
    #     def __init__(self, s=0, e=0):
    #         self.start = s
    #         self.end = e
    
    class Solution(object):
        def eraseOverlapIntervals(self, intervals):
            """
            :type intervals: List[Interval]
            :rtype: int
            """
            if len(intervals) == 0:
                return 0
            intervals.sort(key=lambda x:x.end)
            result,end = 0 , intervals[0].end
            for i in range (1,len(intervals)):
                if intervals[i].start<end:
                    result+=1
                else:
                    end = intervals[i].end
            return result

Log in to reply
 

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