Skip to content

Latest commit

 

History

History
24 lines (22 loc) · 751 Bytes

435. Non-overlapping Intervals.md

File metadata and controls

24 lines (22 loc) · 751 Bytes

435. Non-overlapping Intervals

  1. sort the list by end.
  2. use one end vairable and the begining of each interval to determin all the overlapping intervals. Then count ++.
  3. if there no overlapping interval move end to this end and perform step 1 again.
class Solution(object):
    def eraseOverlapIntervals(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: int
        """
        intervals.sort(key = lambda x:x[1])
        # max + min = -1 because of 2s complement
        end = -sys.maxint - 1
        count = 0
        for oneInterval in intervals:
            if oneInterval[0] < end:
                count += 1
            else:
                end = oneInterval[1]
        return count