当前位置:网站首页>LeetCode_ 455_ Distribute cookies
LeetCode_ 455_ Distribute cookies
2022-07-23 17:34:00 【Fitz1318】
Topic link
Title Description
Suppose you are a great parent , Want to give your kids some cookies . however , Each child can only give one biscuit at most .
For every child i, All have an appetite value g[i], This is the smallest size of biscuit that can satisfy children's appetite ; And every cookie j, They all come in one size s[j] . If s[j] >= g[i], We can put this biscuit j Assign to children i , The child will be satisfied . Your goal is to meet as many children as possible , And output the maximum value .
Example 1:
Input : g = [1,2,3], s = [1,1]
Output : 1
explain :
You have three children and two biscuits ,3 The appetites of a child are :1,2,3.
Although you have two biscuits , Because they are all of the same size 1, You can only make your appetite worth 1 The children of .
So you should output 1.
Example 2:
Input : g = [1,2], s = [1,2,3]
Output : 2
explain :
You have two children and three biscuits ,2 The appetites of a child are 1,2.
You have enough cookies and sizes to satisfy all children .
So you should output 2.
Tips :
1 <= g.length <= 3 * 10^40 <= s.length <= 3 * 10^41 <= g[i], s[j] <= 2^(31) - 1
Their thinking
The law of greed
Give priority to biscuits , Little biscuits give me a little appetite first
AC Code
class Solution {
public int findContentChildren(int[] g, int[] s) {
Arrays.sort(g);
Arrays.sort(s);
int ans = 0;
int j = 0;
for (int i = 0; i < s.length && j < g.length; i++) {
if (s[i] >= g[j]) {
j++;
ans++;
}
}
return ans;
}
}
边栏推荐
- 项目中遇到的问题及解决
- Shrimp noodles: what do you know about the JVM memory layout?
- Food safety | ham sausage lunch meat, is it really so unbearable?
- Single cell literature learning (part6) -- forestfireclustering for SC sequencing combinations iterative label promotion with
- 转账业务追加日志(事务的传播行为).
- 面试官:如何用 Redis 实现分布式锁?
- Program environment and pretreatment
- Visual computer room management
- Detailed explanation of SQL bool blind note and time blind note
- KV260单板PS控制设置IIC开关芯片
猜你喜欢

Kubernetes focuses on kubelet's responsibilities

工业物联网中的时序数据

Kubernetes kubelet hard core knowledge architecture

Encapsulate the general connection and query of the project with pymysql

12 pictures +6k figure ZGC garbage collector and tuning skills
![[MySQL Cluster fault recovery]](/img/bf/8073831d810293170c62356757c368.png)
[MySQL Cluster fault recovery]

Search Binary Tree - find nodes, insert nodes, delete nodes

深入理解机械系统的模态与振动

Interviewer: what is the possible reason for the slow query of MySQL database besides the index problem?

59. General knowledge of lightning safety
随机推荐
“如今,代码数已膨胀至天文级别”
Software configuration | Anaconda download, installation, environment configuration and uninstall
SQL报错盲注详解
使用 PreparedStatement 的 JDBC 程序示例
Explain SQL optimization in detail
Thoughts on software quality system
True title of Blue Bridge Cup: Card [easy to understand]
Geometric parametric reconstruction
转账业务追加日志(事务的传播行为).
Can debug/release versions of dynamic library *.dll files be mixed (cross used)?
How to refine the operation of small program mall?
Emgu CV3+C#图像处理(四):使用EmguCV获取摄像头、读取视频
食品安全|喝鲜奶可能感染结核病?带你了解什么是牛奶灭菌
isEmpty 和 isBlank 的用法区别,至少一半的人答不上来...
日期格式化
Récursion des bosses 1: formule récursive
Three things programmers want to do most | comics
Kv260 single board PS control setting IIC switch chip
5秒到1秒,记一次效果“非常”显著的性能优化
文献学习(part100)--An Introduction to Autoencoders