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
相关推荐
先做个垃圾出来………4 小时前
如何培养自己工程化的能力(python项目)
开发语言·python
mortimer5 小时前
Hugging Face 下载模型踩坑记:从符号链接到网络错误
人工智能·python·ai编程
现在,此刻5 小时前
leetcode 11. 盛最多水的容器 -java
java·算法·leetcode
amazinging6 小时前
北京-4年功能测试2年空窗-报培训班学测开-第七十三天-投递简历-[特殊字符][特殊字符]
python·学习
☆璇6 小时前
【C++】哈希的应用:位图和布隆过滤器
算法·哈希算法
一株月见草哇7 小时前
Matlab(4)
人工智能·算法·matlab
IMER SIMPLE7 小时前
人工智能-python-机器学习-线性回归与梯度下降:理论与实践
人工智能·python·机器学习
hans汉斯8 小时前
基于深度学习的苹果品质智能检测算法研究
人工智能·深度学习·算法
胖墩会武术8 小时前
【图像处理】小波变换(Wavelet Transform,WT)
图像处理·python
火车叨位去19498 小时前
力扣top100(day01-05)--矩阵
算法·leetcode·矩阵