class Solution {
public:
int distributeCandies(vector<int>& candies) {
int res = 0;
unordered_map<int, vector<int>> map;
for (int i =0; i<candies.size(); i++) {
map[candies[i]].push_back(candies[i]);
}
if (map.size()<=candies.size()/2) {
return map.size();
}else{
return candies.size()/2;
}
}
};
Distribute Candies
Copyright © 2017 Powered by LZH, Theme used GitHub CSS.