Update 0452.用最少数量的箭引爆气球.md

Added python version code
This commit is contained in:
LiangDazhu
2021-05-19 23:23:38 +08:00
committed by GitHub
parent 786137dd7b
commit 8efc21f92d

View File

@ -70,7 +70,7 @@
其实都可以只不过对应的遍历顺序不同我就按照气球的起始位置排序了
既然按照其实位置排序那么就从前向后遍历气球数组靠左尽可能让气球重复
既然按照起始位置排序那么就从前向后遍历气球数组靠左尽可能让气球重复
从前向后遍历遇到重叠的气球了怎么办
@ -167,7 +167,19 @@ class Solution {
```
Python
```python
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
if len(points) == 0: return 0
points.sort(key=lambda x: x[0])
result = 1
for i in range(1, len(points)):
if points[i][0] > points[i - 1][1]: # 气球i和气球i-1不挨着注意这里不是>=
result += 1
else:
points[i][1] = min(points[i - 1][1], points[i][1]) # 更新重叠气球最小右边界
return result
```
Go
@ -178,4 +190,4 @@ Go
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>