提交 70162246 编写于 作者: E Ed

Add 452 python3 version

上级 8b8f4135
# 贪心算法之区间调度问题
# 贪心算法之区间调度问题
<p align='center'>
......@@ -158,4 +158,43 @@ int findMinArrowShots(int[][] intvs) {
<img src="../pictures/qrcode.jpg" width=200 >
</p>
======其他语言代码======
\ No newline at end of file
======其他语言代码======
[Edwenc](https://github.com/Edwenc) 提供 第452题的python3 代码:
```python3
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
### 思路是把气球的左右坐标看成是区间
### 用最少数量的箭 相当于 找不重叠区间的个数
### 因为重叠的区间 用一支箭就可以全部引爆气球
# 首先获得区间的个数 为0的话就不用移除
n = len(points)
if n==0:
return 0
# 按照每个区间的右端点值进行排序
sorted_point = sorted( points , key=lambda x: x[1] )
# 不重叠区间个数至少是1
res = 1
# end是所有不重叠的区间中 最大的右端点
# end的初始值即是sorted_list[0]的右端点
end = sorted_point[0][1]
# 从序号1开始往后找
for i in range(1,n):
# start是当前区间左端点值
start = sorted_point[i][0]
# 如果当前左端点比最大右端点都严格大了
# 说明两区间严格不重叠 count+1 再更新end
if start > end:
res += 1
end = sorted_point[i][1]
return res
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册