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
相关推荐
GreenTea4 小时前
深度解读 Anthropic 多智能体报告:更强的模型 ≠ 更好的协调
前端·后端·算法
2603_965148114 小时前
如何解析JSON数据?API返回的商品信息处理教程
开发语言·数据库·python·自动化·json·api
fqq35 小时前
力扣刷题前置Java语法
算法·leetcode·职场和发展
jufeng13075 小时前
【系列:手搓自主 AI Agent:Hermes 架构原理剖析 · 第 8 篇】
python·ai agent·配置系统
circuitsosk6 小时前
跨境电商智能化实战:AI如何赋能客服自动回复、广告智能投放与供应链预测
大数据·人工智能·python·langchain·智能客服
2601_956319886 小时前
2026年零基础学量化:从看懂示例到写清条件和动作
人工智能·python
Thecozzy7 小时前
大厂 AI Coding 面试大招
人工智能·面试·职场和发展
过期的秋刀鱼!7 小时前
LangChain-D1-模型的工作流程
人工智能·python·langchain
半夏微凉半夏殇7 小时前
x11与weston对比,优先选哪个
leetcode·均值算法·eclipse
2501_906565127 小时前
数学之美探究
算法