题目链接:https://leetcode-cn.com/problems/assign-cookies/
题目如下:
class Solution {
public:
int findContentChildren(vector<int>& g, vector<int>& s) {
//贪心,先用最大的饼干满足胃口最大的小孩,依次向后遍历
sort(g.begin(),g.end());//胃口
sort(s.begin(),s.end());//尺寸
int s_index=s.size()-1;
int result=0;
for(int i=g.size()-1;i>=0;i--){
if(s_index<0) break;
if(s_index>=0&&s[s_index]>=g[i]){
s_index--;
result++;
}
}
return result;
}
};