LeetCode(力扣)452. 用最少数量的箭引爆气球Python

LeetCode452. 用最少数量的箭引爆气球

    • 题目链接
    • 代码

题目链接

https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/description/
LeetCode(力扣)452. 用最少数量的箭引爆气球Python_第1张图片

代码

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 - 1][1] < points[i][0]:
                result += 1
            else:
                points[i][1] = min(points[i][1], points[i - 1][1])
        return result

你可能感兴趣的:(leetcode,python,算法,职场和发展)