/**
* @param {number[]} g
* @param {number[]} s
* @return {number}
*/
var findContentChildren = function(g, s) {
g.sort((a, b) => a - b);
s.sort((a, b) => a - b);
let res = 0;
let gLen = g.length;
let sLen = s.length;
let gIndex = 0;
let sIndex = 0;
while(gIndex < gLen && sIndex < sLen) {
if(g[gIndex] <= s[sIndex]) {
res++;
gIndex++;
sIndex++;
} else {
sIndex ++;
}
}
return res
};
複製代碼