问题描述 链接到标题

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();
    }
};