```
public class Solution {
public int distributeCandies(int[] candies) {
HashSet<Integer> set = new HashSet();
int maxCandies = candies.length/2;
int differentCandies = 0;
for(int i = 0; i<candies.length;i++){
if(!set.contains(candies[i])){
set.add(candies[i]);
differentCandies++;
}
}
if(differentCandies<=maxCandies)
return differentCandies;
else return maxCandies;
}
}
```