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
相关推荐
用什么都重名1 小时前
MinerU:高效智能PDF文档解析工具完全指南
人工智能·python·pdf·mineru·makedown
倔强青铜三1 小时前
苦练Python第4天:Python变量与数据类型入门
前端·后端·python
地平线开发者1 小时前
征程 6M 部署 Omnidet 感知模型
算法·自动驾驶
这我可不懂2 小时前
Python 项目快速部署到 Linux 服务器基础教程
linux·服务器·python
倔强青铜三2 小时前
苦练Python第3天:Hello, World! + input()
前端·后端·python
小白学大数据2 小时前
Python爬取闲鱼价格趋势并可视化分析
开发语言·python
秋说2 小时前
【PTA数据结构 | C语言版】线性表循环右移
c语言·数据结构·算法
七月初七淮水竹亭~2 小时前
Pycharm 报错 Environment location directory is not empty 如何解决
ide·python·pycharm
倔强青铜三2 小时前
苦练Python第2天:安装 Python 与设置环境
前端·后端·python
布语world2 小时前
2025快手创作者中心发布视频python实现
爬虫·python