Give each child at most one cookie - 각 어린이마다 최대 하나의 쿠키를 줘야 함
Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with.
Each cookie j has a size s[j]
If s[j] ≥ g[i], we can assign the cookie j to the child i, and the child i will be content.
Goal: maximize the number of your content children and output the maximum number
Solution
var findContentChildren = function (g, s) {
g.sort((a, b) => a - b);
s.sort((a, b) => b - a);
let answer = 0;
for (let i = 0; i < g.length; i++) {
if (!s.length) return answer;
const child = g[i];
while (s.length) {
const cookie = s.pop();
if (child <= cookie) {
answer++;
break;
} else {
continue;
}
}
}
return answer;
};