Leetcode刷题记录——452、用最少数量的箭引爆气球
程序员文章站
2024-03-08 23:02:10
...
我们考虑按照每个区间的max排序
然后从最小的max的区间的max处那里射,
看每一次能射掉多少,
然后再取没被射爆的最小的max的区间,再从max射,统计次数
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
上一篇: 华为机试(7)取近似值
下一篇: 452. 用最少数量的箭引爆气球