当前位置:网站首页>2022.07.14_Daily Question
2022.07.14_Daily Question
2022-07-31 07:39:00 【No. い】
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 * 104
0 <= s.length <= 3 * 104
1 <= 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;
}
}
边栏推荐
- 双倍数据速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM)- 逻辑描述部分
- 安装gstreamer开发依赖库到项目sysroot目录
- Obtaining server and client information
- 【科普向】5G核心网架构和关键技术
- 知识、创新、回报。
- 电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
- 解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie
- codec2 BlockPool:不可读库
- Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题
- Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software
猜你喜欢
Run the NPM will pop up to ask "how are you going to open this file?"
自动翻译软件-批量批量自动翻译软件推荐
文件 - 04 下载文件: 根据文件下载链接下载文件
Zotero | Zotero translator plugin update | Solve the problem that Baidu academic literature cannot be obtained
Conditional statements of shell (test, if, case)
【微服务】Nacos集群搭建以及加载文件配置
【C语言项目合集】这十个入门必备练手项目,让C语言对你来说不再难学!
Explain the example + detail the difference between @Resource and @Autowired annotations (the most complete in the entire network)
基金投顾业务
LeetCode brush # 376 # Medium - swing sequence
随机推荐
线程中断方法
单点登录 思维导图
postgresql源码学习(33)—— 事务日志⑨ - 从insert记录看日志写入整体流程
Bulk free text translation
Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
Moment.js common methods
高并发与多线程之间的难点对比(容易混淆)
庐山谣寄卢侍御虚舟
讲解实例+详细介绍@Resource与@Autowired注解的区别(全网最全)
【 TA - frost Wolf _may - "one hundred plan" 】 art 2.3 hard surface
【微服务】Nacos集群搭建以及加载文件配置
How to choose a suitable UI component library in uni-app
小实战项目之——吃货联盟订餐系统
搭建zabbix监控及邮件报警(超详细教学)
mysql索引失效的常见9种原因详解
【Star项目】小帽飞机大战(七)
nohup原理
Automatic translation software - batch batch automatic translation software recommendation
2. (1) Chained storage of stack, operation of chain stack (illustration, comment, code)
【Go】Go 语言切片(Slice)