分配饼干作者:Geekwyz
题目链接
https://leetcode-cn.com/problems/assign-cookies/
这一题直接贪心的解法
思路:
让饥饿度最小的孩子吃上大于孩子饥饿度且最小的饼干
class Solution {
public:
int findContentChildren(vector& g, vector& s) {
sort(g.begin(),g.end());
sort(s.begin(),s.end());
int ch = 0;//孩子从0开始
int co = 0;
while (ch < g.size() && co < s.size()) {
if (g[ch] <= s[co]) ++ch;
++co;//无论如何也要移动
}
return ch;
}
};



