[leetcode]assign-cookies. 分发饼干

. - 力扣(LeetCode)

复制代码
class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());
        int m = g.size(), n = s.size();
        int count = 0;
        for (int i = 0, j = 0; i < m && j < n; i++, j++) {
            while (j < n && g[i] > s[j]) {
                j++;
            }
            if (j < n) {
                count++;
            }
        }
        return count;
    }
};
相关推荐
一条大祥脚20 小时前
26.1.3 快速幂+容斥 树上dp+快速幂 带前缀和的快速幂 正序转倒序 子序列自动机 线段树维护滑窗
数据结构·算法
二狗哈20 小时前
czsc入门5: Tick RawBar(原始k线) NewBar (新K线)
算法·czsc
Tisfy20 小时前
LeetCode 0865.具有所有最深节点的最小子树:深度优先搜索(一次DFS + Python5行)
算法·leetcode·深度优先·dfs·题解
Q741_14720 小时前
C++ 队列 宽度优先搜索 BFS 力扣 429. N 叉树的层序遍历 C++ 每日一题
c++·算法·leetcode·bfs·宽度优先
Yzzz-F20 小时前
P4145 上帝造题的七分钟 2 / 花神游历各国[线段树 区间开方(剪枝) + 区间求和]
算法·机器学习·剪枝
Zzz不能停21 小时前
堆排序算法及大小堆区别
数据结构·算法
zd84510150021 小时前
stm32f407 电机多轴联动算法
stm32·单片机·算法
代码游侠21 小时前
应用——Linux FrameBuffer图形显示与多线程消息系统项目
linux·运维·服务器·开发语言·前端·算法
Eloudy21 小时前
矩阵张量积(Kronecker积)的代数性质与定理
算法·量子计算
多米Domi01121 小时前
0x3f 第25天 黑马web (145-167)hot100链表
数据结构·python·算法·leetcode·链表