Merge pull request #204 from LiangDazhu/patch-12

添加 0435.无重叠区间 python版本
This commit is contained in:
Carl Sun 2021-05-21 09:35:26 +08:00 committed by GitHub
commit 2492b9c1f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -212,7 +212,19 @@ class Solution {
```
Python
```python
class Solution:
def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:
if len(intervals) == 0: return 0
intervals.sort(key=lambda x: x[1])
count = 1 # 记录非交叉区间的个数
end = intervals[0][1] # 记录区间分割点
for i in range(1, len(intervals)):
if end <= intervals[i][0]:
count += 1
end = intervals[i][1]
return len(intervals) - count
```
Go