Description Link to heading
Solution Link to heading
The optimal way is to eat only one candy for each kind of candy.
Code Link to heading
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();
}
};