Leetcode 575 Solution
This article provides solution to leetcode question 575 (distribute-candies)
Access this page by simply typing in "lcs 575" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/distribute-candies
Solution
class Solution {
public:
int distributeCandies(vector<int>& candies) {
sort(candies.begin(), candies.end());
int last_candy = -100001;
int types = 0;
for (auto candy: candies)
{
if (candy != last_candy)
types++;
last_candy = candy;
}
return min((int)candies.size() / 2, types);
}
};