Day35 ● 860.柠檬水找零 ● 406.根据身高重建队列 ● 452. 用最少数量的箭引爆气球

● 860.柠檬水找零

class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        five=ten=0
        for bill in bills:
            if bill==5:
                five+=1
            elif bill==10:
                five-=1
                ten+=1
            elif bill==20 and ten!=0:
                five-=1
                ten-=1
            else:
                five-=3
            if five<0:
                return False
        return 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:
            return
        points=sorted(points,key=lambda x:(x[0]))
        res=1
        for i in range(1,len(points)):
            if points[i][0]>points[i-1][1]:
                res+=1
            else:
                points[i][1]=min(points[i][1],points[i-1][1])
        return res

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-28 00:24:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-28 00:24:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-28 00:24:03       82 阅读
  4. Python语言-面向对象

    2024-03-28 00:24:03       91 阅读

热门阅读

  1. 【机器学习】如何计算解释模型的SHAP值

    2024-03-28 00:24:03       41 阅读
  2. 华为机试真题练习汇总(101~110)

    2024-03-28 00:24:03       37 阅读
  3. 新建uni-modules插件

    2024-03-28 00:24:03       39 阅读
  4. 前端理论总结(js)——闭包和内存泄漏

    2024-03-28 00:24:03       42 阅读
  5. 关于远程调试应用中的网页鸿蒙

    2024-03-28 00:24:03       38 阅读
  6. 面试算法-118-用队列实现栈

    2024-03-28 00:24:03       40 阅读
  7. [c++] 自写 MyString 类

    2024-03-28 00:24:03       35 阅读
  8. ShardingSphere对国产数据库的支持

    2024-03-28 00:24:03       36 阅读
  9. 《装饰器模式(极简c++)》

    2024-03-28 00:24:03       30 阅读
  10. LCR 001. 两数相除

    2024-03-28 00:24:03       36 阅读
  11. 大话设计模式之简单工厂模式

    2024-03-28 00:24:03       39 阅读