用最少数量的箭引爆气球-贪心452-python
没看答案,和重叠区间问题类似,只不过按照题意,区间首尾相接也算重叠。
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
points = sorted(points, key=lambda x:[x[1], x[0]])
count = 1
end = points[0][1]
for balloon in points:
if balloon[0] > end:
count += 1
end = balloon[1]
return count
共有 0 条评论