本文内容来自公众号 labuladong、LeetCode官网、CSDN" 执 梗 "博主文章“蓝桥杯真题五”、廖雪峰的Python教程、快速幂算法参考的博主文章、全排列参考的博主文章,作者只是搬运和整理
一、贪心算法
class Solution: def eraseOverlapIntervals(self, intervals: List[List[int]]): if not intervals: return(0) intervals.sort(key=lambda x:x[1]) n=len(intervals) ans=1 right=intervals[0][1] for i in range(1,n): if intervals[i][0]>=right: ans+=1 right=intervals[i][1] return(n-ans)
points.sort(