当前位置:网站首页>2022.07.14_每日一题
2022.07.14_每日一题
2022-07-31 06:07:00 【诺.い】
455. 分发饼干
题目描述
假设你是一位很棒的家长,想要给你的孩子们一些小饼干。但是,每个孩子最多只能给一块饼干。
对每个孩子 i,都有一个胃口值 g[i],这是能让孩子们满足胃口的饼干的最小尺寸;并且每块饼干 j,都有一个尺寸 s[j]。如果 s[j] >= g[i],我们可以将这个饼干 j 分配给孩子 i ,这个孩子会得到满足。你的目标是尽可能满足越多数量的孩子,并输出这个最大数值。
示例 1:
输入: g = [1,2,3], s = [1,1]
输出: 1
解释:
你有三个孩子和两块小饼干,3个孩子的胃口值分别是:1,2,3。
虽然你有两块小饼干,由于他们的尺寸都是1,你只能让胃口值是1的孩子满足。
所以你应该输出1。
示例 2:
输入: g = [1,2], s = [1,2,3]
输出: 2
解释:
你有两个孩子和三块小饼干,2个孩子的胃口值分别是1,2。
你拥有的饼干数量和尺寸都足以让所有孩子满足。
所以你应该输出2.
提示:
1 <= g.length <= 3 * 1040 <= s.length <= 3 * 1041 <= g[i], s[j] <= 231 - 1
- 贪心
- 数组
- 排序
coding
class Solution {
public int findContentChildren(int[] g, int[] s) {
int res = 0;
int index = 0;
int cookieCnt = s.length;
Arrays.sort(g);
Arrays.sort(s);
for (int cookie : g) {
while (index < cookieCnt && s[index] < cookie) {
index ++;
}
if (index == cookieCnt) {
break;
}
index ++;
res ++;
}
return res;
}
}
边栏推荐
- 【解决】npm ERR A complete log of this run can be found in npm ERR
- leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
- 文件 - 03 下载文件:根据文件id获取下载链接
- Some derivation formulas for machine learning backpropagation
- Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
- [PSQL] SQL基础教程读书笔记(Chapter1-4)
- Zabbix6.2惊喜发布!特别优化中大型环境部署的性能!
- HighTec 的安装与配置
- 从 Google 离职,前Go 语言负责人跳槽小公司
- 科普 | “大姨太”ETH 和 “小姨太”ETC的爱恨情仇
猜你喜欢

高并发与多线程之间的难点对比(容易混淆)

【TA-霜狼_may-《百人计划》】美术2.3 硬表面基础

单点登录 思维导图

事务的传播机制

Leetcode952. 按公因数计算最大组件大小

解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie

MySQL的触发器
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?

Database Principles Homework 2 — JMU

【微服务】(十六)—— 分布式事务Seata
随机推荐
强化学习科研知识必备(数据库、期刊、会议、牛人)
嵌入式系统驱动初级【2】——内核模块下_参数和依赖
【解决】mysql本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止
数据库概论 - MySQL的简单介绍
Chapter 17: go back to find the entrance to the specified traverse, "ma bu" or horse stance just look greedy, no back to search traversal, "ma bu" or horse stance just look recursive search NXM board
Jobject 使用
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
DirectExchange交换机简单入门demo
【Go报错】go go.mod file not found in current directory or any parent directory 错误解决
In-depth analysis of z-index
新瓶陈酒 --- 矩阵快速幂
Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题
CHI论文阅读(1)EmoGlass: an End-to-End AI-Enabled Wearable Platform for Enhancing Self-Awareness of Emoti
postgresql源码学习(33)—— 事务日志⑨ - 从insert记录看日志写入整体流程
文件 - 03 下载文件:根据文件id获取下载链接
【Go】Go 语言切片(Slice)
【微服务】Nacos集群搭建以及加载文件配置
Bulk free text translation
什么是半波整流器?半波整流器的使用方法
剑指offer(一)