当前位置:网站首页>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 * 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;
}
}
边栏推荐
- 电压源的电路分析知识分享
- postgresql源码学习(33)—— 事务日志⑨ - 从insert记录看日志写入整体流程
- Obtaining server and client information
- 2. (1) Chained storage of stack, operation of chain stack (illustration, comment, code)
- 讲解实例+详细介绍@Resource与@Autowired注解的区别(全网最全)
- 熟悉而陌生的新朋友——IAsyncDisposable
- 2022.07.18_每日一题
- 03-SDRAM: Write operation (burst)
- Kubernetes scheduling
- SQL Server Datetime2数据类型
猜你喜欢

什么是半波整流器?半波整流器的使用方法

Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record

Automatic translation software - batch batch automatic translation software recommendation

基金投顾业务

Some derivation formulas for machine learning backpropagation

2. (1) Chained storage of stack, operation of chain stack (illustration, comment, code)

【C语言项目合集】这十个入门必备练手项目,让C语言对你来说不再难学!

批量免费文字翻译

从 Google 离职,前Go 语言负责人跳槽小公司

讲解实例+详细介绍@Resource与@Autowired注解的区别(全网最全)
随机推荐
【Star项目】小帽飞机大战(八)
自动翻译软件-批量批量自动翻译软件推荐
文件 - 04 下载文件: 根据文件下载链接下载文件
Run the NPM will pop up to ask "how are you going to open this file?"
从 Google 离职,前Go 语言负责人跳槽小公司
【微服务】 微服务学习笔记二:Eureka注册中心的介绍及搭建
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
安装gstreamer开发依赖库到项目sysroot目录
SCI写作指南
2022.07.12_每日一题
2022.07.14_每日一题
【面试:并发篇38:多线程:线程池】ThreadPoolExecutor类的基本概念
04-SDRAM:读操作(突发)
tidyverse笔记——tidyr包
从入门到一位合格的爬虫师,这几点很重要
bcos简介及自序
HighTec 的安装与配置
服务器和客户端信息的获取
360 push-360 push tool-360 batch push tool
SQLite数据库连接字符串