860.柠檬水找零
class Solution:def lemonadeChange(self, bills: List[int]) -> bool:five, ten, twenty = 0, 0, 0for bill in bills:if bill == 5:five += 1elif bill == 10:if five <= 0:return Falsefive -= 1ten += 1elif bill == 20:if ten > 0 and five > 0:ten -= 1five -= 1twenty += 1elif five >= 3:five -= 3twenty += 1else:return Falsereturn True
406.根据身高重建队列
class Solution:def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:# 先按身高降序排,升高相同再按 k 的升序排people.sort(key=lambda x:(-x[0], x[1]))que = []# 再按 k 插入到 people 数组for i in people:que.insert(i[1], i)return que
452. 用最少数量的箭引爆气球
class Solution:def findMinArrowShots(self, points: List[List[int]]) -> int:points.sort(key=lambda x: (x[0], x[1]))count = 1for i in range(1, len(points)):# 不在区间内或者弓箭位置不在区间内if points[i][0] > points[i-1][1]:count += 1else: # 更新右边界 points[i][1] = min(points[i-1][1], points[i][1])return count