575. Distribute Candies

1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public int distributeCandies(int[] candyType) {
int candies = candyType.length / 2;

Set<Integer> typeSet = new HashSet<>();
for (int t : candyType) {
typeSet.add(t);
}

return Math.min(candies, typeSet.size());
}
}

References

575. Distribute Candies