classSolution:deflemonadeChange(self, bills: List[int])->bool:
five =0
ten =0for money in bills:if money ==5:
five+=1if money ==10:if five>0:
five-=1
ten+=1else:returnFalseif money ==20:if ten>0and five>0:
ten-=1
five-=1elif five>2:
five-=3else:returnFalsereturnTrue
根据身高重建队列 (LC 406)
题目思路:
代码实现:
classSolution:defreconstructQueue(self, people: List[List[int]])-> List[List[int]]:
people.sort(key =lambda x:(-x[0],x[1]))
result =[]for i inrange(len(people)):
result.insert(people[i][1], people[i])return result
用最少数量的箭引爆气球 (LC 452)
题目思路:
代码实现:
classSolution:deffindMinArrowShots(self, points: List[List[int]])->int:
points.sort(key =lambda x: x[0])
sr = points[0][1]
count =1for i in points:if i[0]>sr:
count+=1
sr = i[1]else:
sr =min(sr,i[1])return count