LC #455 JS

pimkle發表於2019-04-04
/**
 * @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
};
複製程式碼

相關文章