当前位置:网站首页>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;
}
}
边栏推荐
- LeetCode刷题——摆动序列#376#Medium
- Obtaining server and client information
- 03-SDRAM:写操作(突发)
- Analysis of pseudo-classes and pseudo-elements
- 解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
- 双倍数据速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM)- 逻辑描述部分
- tidyverse笔记——tidyr包
- Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
- QFileInfo常规方法
- Database Principles Homework 2 — JMU
猜你喜欢

(border-box) The difference between box model w3c and IE

从入门到一位合格的爬虫师,这几点很重要

Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning

Analysis of the principle and implementation of waterfall flow layout

我开发了一个利用 Bun 执行 .ts / .js 文件的 VS Code 插件

【第四章】详解Feign的实现原理

postgresql源码学习(34)—— 事务日志⑩ - 全页写机制

【网络攻防】常见的网络攻防技术——黑客攻防(通俗易懂版)

单点登录 思维导图

Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
随机推荐
关于求反三角函数的三角函数值
2022.07.29_每日一题
线程中断方法
tidyverse笔记——dplyr包
【科普向】5G核心网架构和关键技术
新瓶陈酒 --- 矩阵快速幂
Analysis of the implementation principle and detailed knowledge of v-model syntactic sugar and how to make the components you develop support v-model
一文读懂 MongoDB 和 MySQL 的差异
04-SDRAM:读操作(突发)
【面试:并发篇38:多线程:线程池】ThreadPoolExecutor类的基本概念
【面试:并发篇37:多线程:线程池】自定义线程池
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
事务的四大特性
Third-party library-store
SCI写作指南
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
文件 - 02 上传文件:上传临时文件到服务器
把 VS Code 当游戏机
Gradle剔除依赖演示
Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning