455. Assign Cookies
来源:互联网 发布:node wiki 编辑:程序博客网 时间:2024/05/17 01:20
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cookie that the child will be content with; and each cookie j has a size sj. If sj >= gi, we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.
这道题就是先通过排序,然后满足的饼干就分给那个孩子。
代码如下:
class Solution {public: int findContentChildren(vector<int>& g, vector<int>& s) { sort(g.begin(),g.end()); sort(s.begin(),s.end()); int count=0; for(int i=0,j=0;i<g.size()&&j<s.size();j++){ if(g[i]<=s[j]){ i++; count++; } } return count; }};
阅读全文
0 0
- LeetCode 455. Assign Cookies
- 455. Assign Cookies
- Leetcode-455. Assign Cookies
- 455. Assign Cookies
- 455. Assign Cookies
- LeetCode 455. Assign Cookies
- 455. Assign Cookies
- 【LeetCode】455. Assign Cookies
- leetcode 455. Assign Cookies
- 455. [LeetCode]Assign Cookies
- [leetcode] 455. Assign Cookies
- 455. Assign Cookies
- 【LeetCode】 455. Assign Cookies
- [LeetCode]455. Assign Cookies
- Leetcode-455. Assign Cookies
- 455. Assign Cookies
- 455. Assign Cookies
- 455. Assign Cookies*
- 谷歌要用AI把你的自拍做成表情包
- Android Gradle Build Error:Some file crunching failed, see logs for details解决办法
- springboot整合freemarker
- 用sqlplus远程连接oracle命令
- 记一次OOM(GC overhead limit exceeded)异常
- 455. Assign Cookies
- 最大子序列和问题求解
- Javaweb QQ邮箱发邮件功能
- 卷积神经网络中same padding 和 valid padding
- 运维工程师必会的109个Linux命令
- 数据结构计算器实现ABS()和SQRT()
- Vimium——Chrome里伟哥级插件
- history.pushState无刷新改变url
- Java多线程和并发性知识点总结