Skip to content

Latest commit

 

History

History
37 lines (32 loc) · 873 Bytes

1288. Remove Covered Intervals.md

File metadata and controls

37 lines (32 loc) · 873 Bytes

1288. Remove Covered Intervals

  1. sorted by start time x[0].
  2. when same sorted by -x[1].
-------- end is here
------
---
 ---
  ------- update end in this step.
  1. using a end variable to determine if the new interval is included by the previous one.
  2. if end < oneInterval[1], count ++. upadte end.
class Solution(object):
    def removeCoveredIntervals(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: int
        """
        if not intervals:
            return 0
        # sort by starts and reversed end.
        intervals.sort(key = lambda x: (x[0], -x[1]))
        end = 0
        count = 0
        originalCount = len(intervals)
        for oneInterval in intervals:
            if oneInterval[1] > end:
                end = oneInterval[1]
                count += 1
        return count