Skip to content

leetcode-1431 拥有最多糖果的孩子 #174

@GuoLizhi

Description

@GuoLizhi

数组

var kidsWithCandies = function(candies, extraCandies) {
    const result = [];
    // 先求最大值
    let max = Number.MIN_VALUE;
    for (let i = 0; i < candies.length; i++) {
        max = Math.max(max, candies[i]);
    }

    // 再将每一项加上extraCandies后与最大值比较
    for (let i = 0; i < candies.length; i++) {
        result.push(candies[i] + extraCandies >= max);
    }
    return result;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions