classSolution: deffindMinArrowShots(self, points): if len(points) == 0: return0 points.sort(key=lambda p: p[0]) total = 1 overlap = points[0] for point in points: if overlap[1] < point[0]: total += 1 overlap = point else: overlap[0] = point[0] overlap[1] = min(overlap[1], point[1])
return total
Version 2
1 2 3 4 5 6 7 8 9 10 11 12 13
classSolution: deffindMinArrowShots(self, points): if len(points) == 0: return0 points.sort(key=lambda p: p[1]) total = 1 overlap = points[0] for point in points: if overlap[1] < point[0]: total += 1 overlap = point