mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Update 0452.用最少数量的箭引爆气球.md
Added python version code
This commit is contained in:
@ -70,7 +70,7 @@
|
|||||||
|
|
||||||
其实都可以!只不过对应的遍历顺序不同,我就按照气球的起始位置排序了。
|
其实都可以!只不过对应的遍历顺序不同,我就按照气球的起始位置排序了。
|
||||||
|
|
||||||
既然按照其实位置排序,那么就从前向后遍历气球数组,靠左尽可能让气球重复。
|
既然按照起始位置排序,那么就从前向后遍历气球数组,靠左尽可能让气球重复。
|
||||||
|
|
||||||
从前向后遍历遇到重叠的气球了怎么办?
|
从前向后遍历遇到重叠的气球了怎么办?
|
||||||
|
|
||||||
@ -167,7 +167,19 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
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:
|
Go:
|
||||||
|
|
||||||
@ -178,4 +190,4 @@ Go:
|
|||||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
||||||
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
|
* 知识星球:[代码随想录](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>
|
||||||
|
Reference in New Issue
Block a user