Distribute Candies

2017/12/8 posted in  leetcode

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;
        }
    }
};