575.分糖果

发布时间 2023-06-13 16:43:17作者: zwyyy456

问题描述

575.分糖果

解题思路

最优思路为一种糖果只吃一颗。

代码

class Solution {
public:
    int distributeCandies(vector<int>& candyType) {
        int n = candyType.size(), res = n / 2;
        std::unordered_set<int> type;
        for (auto i : candyType)
            type.insert(i);
        return res < type.size() ? res : type.size();
    }
};