452. 用最少数量的箭引爆气球
题目描述
代码实现
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
points = sorted(points, key=lambda x: x[0])
res = 1
pre_right = points[0][1]
for i in range(1, len(points)):
if points[i][0] > pre_right: # 气球i和气球i-1不挨着,注意这里不是>=,新的右边界
res += 1
pre_right = points[i][1]
else:
pre_right = min(pre_right, points[i][1]) # 贪心:同一支箭射中重叠气球的最小右边界
return res