Merge pull request #203 from LiangDazhu/patch-11

添加 0452.用最少数量的箭引爆气球 python版本
This commit is contained in:
Carl Sun 2021-05-21 09:34:55 +08:00 committed by GitHub
commit f860ffb102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

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>