435. Non-overlapping Intervals

435. Non-overlapping Intervals

class Solution:
    def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
        intervals=sorted(intervals)
        i,j=0,1
        ans=0
        while j< len(intervals):
            if intervals[i][1]<=intervals[j][0]:
                i=j
                j+=1
            elif intervals[i][1]<=intervals[j][1]:
                j+=1
                ans+=1
            else:
                i=j
                j+=1
                ans+=1
        return ans

分情况考虑

你可能感兴趣的:(leetcode)