代码随想录 -- 贪心算法 -- 分发饼干

455. 分发饼干 - 力扣(LeetCode)

python 复制代码
class Solution(object):
    def findContentChildren(self, g, s):
        num=0
        g.sort()
        s.sort()
        index=0
        for i in range(len(s)):
            while index<len(g) and s[i]>=g[index]:
                index+=1
                num+=1 
                break
        return num
相关推荐
文丑颜不良啊8 小时前
LeetCode3281~3300题目解析
java·leetcode
地平线开发者9 小时前
让 AI Agent 和 征程6 台架高效、稳定、安全地协作
算法·安全·自动驾驶
kyle~10 小时前
SHA-256 哈希去重
算法·哈希算法
kyle~10 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享11 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者12 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
文丑颜不良啊12 小时前
LeetCode3261~3280题目解析
java·leetcode
MSTcheng.12 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人13 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__13 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python