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
相关推荐
多喝开水少熬夜9 分钟前
损失函数系列:focal-Dice-vgg
图像处理·python·算法·大模型·llm
我命由我1234515 分钟前
Photoshop - Photoshop 工具栏(22)单行选框工具
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
立志成为大牛的小牛32 分钟前
数据结构——三十七、关键路径(王道408)
数据结构·笔记·程序人生·考研·算法
ytttr8731 小时前
基于MATLAB的Relief算法特征权重选择实现
算法
初学小刘1 小时前
基于 U-Net 的医学图像分割
python·opencv·计算机视觉
B站计算机毕业设计之家2 小时前
Python招聘数据分析可视化系统 Boss直聘数据 selenium爬虫 Flask框架 数据清洗(附源码)✅
爬虫·python·selenium·机器学习·数据分析·flask
雪碧聊技术2 小时前
爬虫是什么?
大数据·爬虫·python·数据分析
FL16238631292 小时前
[yolov11改进系列]基于yolov11使用fasternet_t0替换backbone用于轻量化网络的python源码+训练源码
python·yolo·php
Freshman小白2 小时前
python算法打包为docker镜像(边缘端api服务)
python·算法·docker
岁岁岁平安2 小时前
python mysql-connector、PyMySQL基础
python·mysql·pymysql