题目:455. 分发饼干
思路
贪心法
代码
class Solution {
public:int findContentChildren(vector<int>& g, vector<int>& s) {int cookie_i, belly_i, result = 0;// 满足的小孩数 : result// 胃口: g// 饼干: ssort(g.begin(), g.end());sort(s.begin(), s.end());cookie_i = s.size()-1;for(belly_i = g.size()-1; cookie_i >= 0 && belly_i >= 0; belly_i--){if(s[cookie_i] >= g[belly_i]){result++;cookie_i--;}}return result;}
};
遍历的时候对胃口遍历,反过来(对饼干)没用;