作者:Geekwyz
分配饼干
这一题直接贪心的解法
思路:
让饥饿度最小的孩子吃上大于孩子饥饿度且最小的饼干
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& 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;
}
};