0
点赞
收藏
分享

微信扫一扫

[220113] Minimum Number of Arrows to Burst Balloons

class Solution:
    def findMinArrowShots(self, points):

        # 按每个气球的 end 排序
        p = sorted(points, key=lambda x: x[1])
        res = 0
        arrow = p[0][0] - 1

        # 比较每个气球的 start 和 arrow
        for each in p:
            # 需要多一支箭,有效范围到 end
            if each[0] > arrow:
                res += 1
                arrow = each[1]

        return res
举报

相关推荐

0 条评论