LeetCode(力扣)455. 分发饼干Python

LeetCode20. 有效的括号

题目链接

https://leetcode.cn/problems/assign-cookies/![在这里插入图片描述](https://file.jishuzhan.net/article/1701080909790318594/04dd97581b7243328b93651ff221052e.png)

代码

从大遍历

python 复制代码
class Solution:
    def findContentChildren(self, g: List[int], s: List[int]) -> int:
        g.sort()
        s.sort()
        index = len(s) - 1
        result = 0
        for i in range(len(g) - 1, -1, -1):
            if s[index] >= g[i] and index >= 0:
                result += 1
                index -= 1
        return result

从小遍历

python 复制代码
class Solution:
    def findContentChildren(self, g: List[int], s: List[int]) -> int:
        g.sort()
        s.sort()
        index = 0
        for i in range(len(s)):
            if index < len(g) and g[index] <= s[i]:
                index += 1
        return index
相关推荐
未若君雅裁3 小时前
算法复杂度与数据结构:Java 集合篇的第一块基石
java·数据结构·算法
荣码3 小时前
【Python知识详解】变量与数据类型:深入理解 Python 的数据世界
python
春日见4 小时前
五分钟入门 强化学习---Q-Learning算法与实现
人工智能·python·深度学习·算法·机器学习·计算机视觉
weixin_468466854 小时前
Prometheus监控服务部署与实战指南
服务器·后端·python·docker·自动化·prometheus
花酒锄作田4 小时前
[Python]标准库argparse解析命令行参数使用介绍
python
卡次卡次14 小时前
vibecoding起步之注意点:如何做一个聊天机器人
python·ai
Zldaisy3d4 小时前
全球唯一仿真驱动自适应扫描路径新版本发布,金属3D打印工艺开发进入算法时代
算法·3d
Hanniel4 小时前
Python 元类(下):进阶与实战建议
开发语言·python
小江的记录本4 小时前
【JVM虚拟机】类加载机制:类加载全流程:加载→验证→准备→解析→初始化(附《思维导图》+《面试高频考点清单》)
java·jvm·spring boot·算法·安全·spring·面试
mONESY4 小时前
Python 字典(dict):从原理到实战,彻底搞懂哈希表核心
python