当前位置:网站首页>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;
}
}
边栏推荐
- 那些破釜沉舟入局Web3.0的互联网精英都怎么样了?
- 电压源的电路分析知识分享
- 服务器和客户端信息的获取
- 完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
- DirectExchange交换机简单入门demo
- 【编程题】【Scratch三级】2022.03 冬天下雪了
- 线程中断方法
- Analysis of the implementation principle and detailed knowledge of v-model syntactic sugar and how to make the components you develop support v-model
- Basic usage of Koa framework
- Bulk free text translation
猜你喜欢

Run the NPM will pop up to ask "how are you going to open this file?"

【云原生】-Docker容器迁移Oracle到MySQL

Log4net 思维导图

Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software

浅层了解欧拉函数

DirectExchange交换机简单入门demo

How to use repeating-linear-gradient

【微服务】Nacos集群搭建以及加载文件配置

Automatic translation software - batch batch automatic translation software recommendation

360推送-360推送工具-360批量推送工具
随机推荐
高并发与多线程之间的难点对比(容易混淆)
测试 思维导图
Bulk free text translation
Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题
自动翻译软件-批量批量自动翻译软件推荐
Zabbix6.2惊喜发布!特别优化中大型环境部署的性能!
2022.7.29 数组
HighTec 的安装与配置
什么是半波整流器?半波整流器的使用方法
Database Principles Homework 2 — JMU
外贸网站优化-外贸网站优化教程-外贸网站优化软件
MySQL笔记下
What is float?What is document flow?Several ways and principles of clearing floats?What is BFC, how to trigger BFC, the role of BFC
简单谈谈Feign
4-1-7 二叉树及其遍历 家谱处理 (30 分)
Explain the example + detail the difference between @Resource and @Autowired annotations (the most complete in the entire network)
DDL+DML+DQL
基于LSTM的诗词生成
熟悉而陌生的新朋友——IAsyncDisposable
Run the NPM will pop up to ask "how are you going to open this file?"