LeetCode "455. Assign Cookies"

Simple greedy thought .. satify each kid with minimum qualified cookie, from the least greedy kid..

class Solution {
public:
    int findContentChildren(vector<int>& g, vector<int>& s) {
        int ng = g.size();
        int ns = s.size();
        
        sort(g.begin(), g.end());
        sort(s.begin(), s.end());
        
        int ig = 0, is = 0;
        while(ig < ng && is < ns)
        {
            while(is < ns && s[is] < g[ig]) is ++;
            if(is == ns) break;
            
            ig ++; is ++;
        }
        
        return ig;
    }
};
原文地址:https://www.cnblogs.com/tonix/p/6346898.html