455. Assign Cookies
来源:互联网 发布:airserver windows 编辑:程序博客网 时间:2024/05/18 07:14
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()); auto p1=g.cbegin(); auto p2=s.cbegin(); int ans=0; while(p1!=g.cend()&&p2!=s.cend()){ if(*p1<=*p2){ ++p1; ++p2; ++ans; } else { ++p2; } } return ans; }};
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*
- 用FragmentTabhost实现仿京东页面
- 手工设置服务依赖
- MySQL -- FIND_IN_SET("", 字段名)
- Linux-OpenSUSE折腾-1(Qt安装,Chrome安装)
- 不知道写啥最近在学js,就弄一个js的从零开始吧,尽量每天都坚持更新吧!
- 455. Assign Cookies
- Java调优经验谈
- 漫天星月——有点艺术的感觉。
- TextView上面显示不同文字和颜色
- Android Studio 提示 Unsupported method: AndroidProject.getPluginGeneration()的解决方法
- Android学习第四篇;如何将自己的应用编译到源码当中
- 获取iPhone的UDID
- java设计模式之建造者设计模式
- JAVA内存溢出和内存泄漏