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
相关推荐
m0_733612212 分钟前
C++20概念(Concepts)入门指南
开发语言·c++·算法
仰泳的熊猫4 分钟前
题目2571:蓝桥杯2020年第十一届省赛真题-回文日期
数据结构·c++·算法·蓝桥杯
我喜欢就喜欢8 分钟前
基于离散余弦变换的感知哈希算法:原理、实现与工程实践
算法·哈希算法
大连好光景16 分钟前
conda管理包还是pip管理包
python·conda·pip
m0_7301151120 分钟前
自动化机器学习(AutoML)库TPOT使用指南
jvm·数据库·python
FreakStudio28 分钟前
MicroPython+PycoClaw,3 分钟搞定 ESP32 跑上 OpenClaw!
python·单片机·嵌入式·电子diy
2301_8073671931 分钟前
C++中的模板方法模式
开发语言·c++·算法
罗罗攀42 分钟前
PyTorch学习笔记|张量的广播和科学运算
人工智能·pytorch·笔记·python·学习
PhotonixBay1 小时前
共聚焦显微镜的结构组成与应用
人工智能·算法·机器学习
傻啦嘿哟1 小时前
Python 操作 Excel 条件格式指南
开发语言·python·excel