目录
学习目标
- 860.柠檬水找零
- 406.根据身高重建队列
- 452. 用最少数量的箭引爆气球
学习内容
860.柠檬水找零
860. 柠檬水找零 - 力扣(LeetCode)https://leetcode.cn/problems/lemonade-change/
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
a = 0
b = 0
c = 0
for num in bills:
if num==5:
a+=1
elif num==10:
b+=1
if a==0:return False
a-=1
else:
c+=1
if b==0 and a<3 or a==0:
return False
if b!=0:
b-=1
a-=1
else:
a-=3
return True
406.根据身高重建队列
406. 根据身高重建队列 - 力扣(LeetCode)https://leetcode.cn/problems/queue-reconstruction-by-height/
class Solution:
def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
res = []
people.sort(key =lambda x:(-x[0],x[1]))
#print(people)
for item in people:
res.insert(item[1],item)
return res
452. 用最少数量的箭引爆气球
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
res = 1
points.sort(key = lambda x:x[0])
#print(points)
tmp = points[0][1]
for item in points:
if tmp<item[0]:
res+=1
tmp = item[1]
else:
tmp = min(tmp,item[1])
return res