● 860.柠檬水找零
class Solution:def lemonadeChange(self, bills: List[int]) -> bool:five=ten=0for bill in bills:if bill==5:five+=1elif bill==10:five-=1ten+=1elif bill==20 and ten!=0:five-=1ten-=1else:five-=3if five<0:return Falsereturn True
● 406.根据身高重建队列
class Solution:def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:people=sorted(people,key=lambda x:(-x[0],x[1]))res=[]for p in people:if len(res)<=p[1]:res.append(p)elif len(res)>p[1]:res.insert(p[1],p)return res#这里使用了lambda表达式来定义排序规则,lambda x:(-x[0],x[1])表示对于每个元素x,
首先以-x[0]降序排序,然后以x[1]升序排序。
● 452. 用最少数量的箭引爆气球
class Solution:def findMinArrowShots(self, points: List[List[int]]) -> int:if len(points)<0:returnpoints=sorted(points,key=lambda x:(x[0]))res=1for i in range(1,len(points)):if points[i][0]>points[i-1][1]:res+=1else:points[i][1]=min(points[i][1],points[i-1][1])return res