box-lin / miniblog

https://bboxlin.github.io/miniblog/
MIT License
0 stars 0 forks source link

01/04/2022 Two Leetcode Questions #11

Open box-lin opened 1 year ago

box-lin commented 1 year ago

452. Minimum Number of Arrows to Burst Balloons

1229. Meeting Scheduler

137thphxx commented 1 year ago

452.

class Solution:
    def findMinArrowShots(self, points: List[List[int]]) -> int:
        points.sort(key=lambda p: p[1])#根据尾部数值进行sort

        ans, arrow = 0, 0

        #遍历,利用array的尾部数值确定接下来的数组是否在范围内,如果不在,箭矢+1
        for [start, end] in points:
            if ans == 0 or start > arrow:
                ans, arrow = ans + 1, end
        return ans