当前位置:网站首页>Leetcode- distribute cookies - simple
Leetcode- distribute cookies - simple
2022-06-13 05:49:00 【AnWenRen】
title :455 Distribute cookies - Simple
subject
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 * 104
0 <= s.length <= 3 * 104
1 <= g[i], s[j] <= 231 - 1
Code Java
int sum = 0;
Arrays.sort(g);
Arrays.sort(s);
int j;
int index = 0;
for (int i = 0; i < g.length && index < s.length; i++) {
j = index;
while (j < s.length){
if (s[j] >= g[i]) {
sum ++;
break;
}
j++;
}
index = j + 1;
}
return sum;
边栏推荐
- Mongodb Multi - field Aggregation group by
- Working principle of sentinel series (source code analysis)
- Mysql database crud operation
- Mysql database backup and restore:
- Problems encountered in the use of PgSQL
- Shardingsphere JDBC < bind table > avoid join Cartesian product
- Celery understands
- 10 signalstartevent and signalcatchingevent of flowable signal events
- 中断处理过程
- Nacos series registry principle and source code analysis
猜你喜欢
Working principle of sentinel series (concept)
MySQL built-in functions
Mongodb Multi - field Aggregation group by
3. Postman easy to use
NVIDIA Jetson nano/xavier NX capacity expansion tutorial
Django uses redis to store sessions starting from 0
Function and application scenario of field setaccessible() method
Mongodb multi field aggregation group by
Service fusing and degradation of Note Series
为什么那么多人讨厌A-Spice
随机推荐
No assessment summary
Hump naming and underlining
3. Postman easy to use
18 flowable task manualtask and receivetask
Parallelgateway and exclusivegateway of 14 gateways
Error: unmapped character encoding GBK
Current limiting and fusing of gateway gateway in Spirng cloud
OpenGL Mosaic (8)
Feel the power of shardingsphere JDBC through the demo
Pychart professional edition's solution to SQL script error reporting
NVIDIA Jetson Nano/Xavier NX 扩容教程
890. Find and Replace Pattern
OpenGL马赛克(八)
How to Algorithm Evaluation Methods
Windbos run command set
Unity game optimization [Second Edition] learning record 6
Find out the missing numbers from the natural numbers arranged in order from 0 to 100, and the solution provides
Anaconda configuring the mirror source
Working principle of sentinel series (concept)
Concurrent programming -- countdownlatch combined with thread pool