O(n) simple hashset solution


  • 0
    I
        int distributeCandies(vector<int>& candies) {
            unordered_set<int> s;
            for(int i = 0; i < candies.size(); ++i)
               s.insert(candies[i]);
            return min(s.size(),candies.size()/2);
        }
    
    

Log in to reply
 

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