本文共 724 字,大约阅读时间需要 2 分钟。
class Solution { public: int findContentChildren(vector & g, vector & s) { sort(g.begin(), g.end()); sort(s.begin(), s.end()); int numOfChildren = g.size(), numOfCookies = s.size(); int count = 0; for (int i = 0, j = 0; i < numOfChildren && j < numOfCookies; i++, j++) { while (j < numOfCookies && g[i] > s[j]) { j++; } if (j < numOfCookies) { count++; } } return count; }};/*作者:LeetCode-Solution链接:https://leetcode-cn.com/problems/assign-cookies/solution/fen-fa-bing-gan-by-leetcode-solution-50se/来源:力扣(LeetCode)著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。*/