首页 > 代码库 > LeetCode "455. Assign Cookies"

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;    }};

LeetCode "455. Assign Cookies"