编程语言
首页 > 编程语言> > LeetCode题解(1288):删除被覆盖区间(Python)

LeetCode题解(1288):删除被覆盖区间(Python)

作者:互联网

题目:原题链接(中等)

标签:排序、贪心算法、扫描线算法

解法时间复杂度空间复杂度执行用时
Ans 1 (Python) O ( N l o g N ) O(NlogN) O(NlogN) O ( l o g N ) O(logN) O(logN)52ms (50.73%)
Ans 2 (Python)
Ans 3 (Python)

解法一:

class Solution:
    def removeCoveredIntervals(self, intervals: List[List[int]]) -> int:
        intervals.sort(key=lambda x: (x[0], -x[1]))

        ans = len(intervals)

        most_right = 0
        for left, right in intervals:
            if right <= most_right:
                ans -= 1
            else:
                most_right = right

        return ans

标签:right,Python,题解,1288,int,intervals,Ans,NlogN
来源: https://blog.csdn.net/Changxing_J/article/details/112857659