my 5 lines c++ solution that beats 88%


  • 0
        int distributeCandies(vector<int>& candies) {
            std::sort(candies.begin(), candies.end());
            int n = candies.size(), cnt = 0;
            for(int i=0; i<n && cnt < n/2 ;i++)
                if(i+1==n||candies[i] != candies[i+1])cnt++;
            return cnt;
        }
    

  • 0

    I don't think it's necessary to use set.


Log in to reply
 

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