标签:public mini while cookie span blog simple cookies style
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"
标签:public mini while cookie span blog simple cookies style
原文地址:http://www.cnblogs.com/tonix/p/6346898.html