【LeetCode】455. 分发饼干
点击查看代码
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
sort(g.begin(),g.end());
sort(s.begin(),s.end());
int g_size = g.size()-1;
int s_size = s.size()-1;
int num = 0;
while(g_size >= 0 && s_size >= 0){
if(g[g_size] <= s[s_size]){
num++;
g_size--;
s_size--;
}
else{
g_size--;
}
}
return num;
}
};