Skip to content

455. 分发饼干 #55

Open
Open
@swiftwind0405

Description

@swiftwind0405

方法一:贪心算法

解题思想:

代码:

var findContentChildren = function(g, s) {
    const sortFunc = (a, b) => a - b;
    g.sort(sortFunc);
    s.sort(sortFunc);
    let i = 0;
    s.forEach(n => {
        if ( n >= g[i]) {
            i++;
        }
    });
    return i;
};

复杂度分析:

  • 时间复杂度:
  • 空间复杂度:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions