mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0435.无重叠区间.md
Added python version code
This commit is contained in:
@ -212,7 +212,19 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
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:
|
Go:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user