C++, bitset, beats 99.60%


  • 11
    Z

    The idea is to use biset as hash table instead of unordered_set.

    int distributeCandies(vector<int>& candies) {
            bitset<200001> hash;
            int count = 0;
            for (int i : candies) {
                if (!hash.test(i+100000)) {
                   count++;
                   hash.set(i+100000);
                }
            }
            int n = candies.size();
            return min(count, n/2);
        }
    

  • 0
    E

    wow, unexpected operation,impressive!


Log in to reply
 

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