Leetcode brushing record-452. Detonate the balloon with the least number of arrows

Insert picture description here
We consider sorting according to the max of each interval,
then shoot from the max of the smallest max interval,
see how much can be shot each time,
and then take the smallest max interval that has not been exploded, and then shoot from max, statistics frequency

class Solution:
    def __init__(self):
        self.points = None
    def findMinArrowShots(self, points: List[List[int]]) -> int:
        self.points = sorted(points,key=lambda x:x[1])#,x[1]
        suma = 0
        while self.points != []:
            arrow = self.points[0][1]
            self.points.pop(0)
            tempsum = self.inlist(arrow,self.points)
            for i in range(tempsum):
                self.points.pop(0)
            suma += 1
        return suma 
            
    def inlist(self,value,otherlists):
        temp = 0
        for onelist in otherlists:
            if value >= onelist[0]:
                temp += 1
            else:
                break
        return temp
Published 43 original articles · praised 14 · 20,000+ views

Guess you like

Origin blog.csdn.net/weixin_41545780/article/details/105463225