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
相关推荐
花酒锄作田6 小时前
企业微信机器人与 DeepAgents 集成实践
python·mcp·deepagents
likerhood8 小时前
java中`==`和`.equals()`区别
java·开发语言·python
IronMurphy9 小时前
【算法三十九】994. 腐烂的橘子
算法
迷茫的启明星9 小时前
各职业在当前发展阶段,使用AI的舒适区与盲区
大数据·人工智能·职场和发展
qq_283720059 小时前
Python Celery + FastAPI + Vue 全栈异步任务实战
vue.js·python·fastapi
2401_885885049 小时前
营销推广短信接口集成:结合营销策略实现的API接口动态变量填充方案
前端·python
Ares-Wang10 小时前
算法》》旅行商问题 TSP、7座桥问题 哈密顿回路 深度优先 和 宽度优先
算法·深度优先·宽度优先
Liqiuyue10 小时前
Transformer:现代AI革命背后的核心模型
人工智能·算法·机器学习
WolfGang00732110 小时前
代码随想录算法训练营 Day34 | 动态规划 part07
算法·动态规划
telllong10 小时前
Python异步编程从入门到不懵:asyncio实战踩坑7连发
开发语言·python