Distribute Candies

LeetCode題目: 575. Distribute Candies

My solution:

/**
 * @param {number[]} candyType
 * @return {number}
 */
let distributeCandies = candyType => {
    const types = new Set(candyType);
    const halfCandy = candyType.length / 2;
    return types.size >= halfCandy ? halfCandy : types.size;
};
profile-image
Hi, 我是 Zeki。目前為一名前端工程師。我相信科技始終來自於人性,是用來幫助人們過上更有品質的生活的,但願也希望如此。