代码随想录训练营Day35| 860.柠檬水找零 406.根据身高重建队列 452. 用最少数量的箭引爆气球

本文介绍了三道LeetCode上的编程题目,包括在柠檬水销售中处理找零问题、根据身高重建队列以及确定用最少数量的箭来引爆气球的策略。每道题都提供了Python解冔方案,涉及排序、数据结构和优化算法的应用。
摘要由CSDN通过智能技术生成

目录

学习目标

学习内容

 860.柠檬水找零 

406.根据身高重建队列  

  452. 用最少数量的箭引爆气球


学习目标

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

学习内容

 860.柠檬水找零 

860. 柠檬水找零 - 力扣(LeetCode)icon-default.png?t=N3I4https://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)icon-default.png?t=N3I4https://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. 用最少数量的箭引爆气球

452. 用最少数量的箭引爆气球 - 力扣(LeetCode)icon-default.png?t=N3I4https://leetcode.cn/problems/minimum-number-of-arrows-to-burst-balloons/

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值