2026.02.11

860. 柠檬水找零

python 复制代码
class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        cash = [0] * 11
        for i in range(len(bills)):
            if bills[i] == 5:
                cash[5] += 1
            elif bills[i] == 10:
                cash[5] -= 1
                if cash[5] < 0:
                    return False
                cash[10] += 1
            else:
                if cash[10] > 0 and cash[5] > 0:
                    cash[10] -= 1
                    cash[5] -= 1
                elif cash[5] >= 3:
                    cash[5] -= 3
                else:
                    return False
        return True

406. 根据身高重建队列

python 复制代码
class Solution:
    def reconstructQueue(self, people: List[List[int]]) -> List[List[int]]:
        people.sort(key = lambda x: (-x[0], x[1]))

        que = []
        for p in people:
            que.insert(p[1], p)
        return que

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

python 复制代码
class Solution:
    def findMinArrowShots(self, points: List[List[int]]) -> int:
        points.sort(key = lambda x : x[1])
        count = 0
        ed = float('-inf')
        for p in points:
            if ed < p[0]:
                count += 1
                ed = p[1]
                
        return count
相关推荐
lly2024061 小时前
Scala IF...ELSE 语句详解
开发语言
百锦再2 小时前
Java重入锁(ReentrantLock)全面解析:从入门到源码深度剖析
java·开发语言·struts·spring·kafka·tomcat·intellij-idea
Electron-er2 小时前
深入解析C语言memcmp函数:内存比较的利器与陷阱(附实战案例)
c语言·开发语言
m0_531237172 小时前
C语言-操作符
c语言·开发语言
AI周红伟2 小时前
周红伟:智能体实战,通过使用 Flask 的 REST API 在 Python 中部署 PyTorch
后端·python·flask
清水白石0082 小时前
Python 性能分析实战指南:timeit、cProfile、line_profiler 从入门到精通
开发语言·python
月光有害2 小时前
深入解析批归一化 (Batch Normalization): 稳定并加速深度学习的基石
开发语言·深度学习·batch
yaoxin5211232 小时前
326. Java Stream API - 实现自定义的 toList() 与 toSet() 收集器
java·开发语言
Cosmoshhhyyy2 小时前
《Effective Java》解读第40条:坚持使用Override注解
java·开发语言