【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;
    }
};
posted @ 2022-08-17 09:18  小超不挑食  阅读(14)  评论(0编辑  收藏  举报