Simple Set Based Solution


  • 0
    K
    class Solution {
    public:
        int distributeCandies(vector<int>& candies) {
            unordered_map<int,int> set;
            
            for(int& x: candies){
                set[x] = 1;
            }
            
            return set.size()*2 >= candies.size()? candies.size()/2 : set.size() ;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.