Fast and concise C++ multiset solution


  • 17
    T
    class TwoSum {
        unordered_multiset<int> nums;
    public:
        void add(int number) {
            nums.insert(number);
        }
        bool find(int value) {
            for (int i : nums) {
                int count = i == value - i ? 1 : 0;
                if (nums.count(value - i) > count) {
                    return true;
                }
            }
            return false;
        }
    };

  • 0
    R

    nice solution!


  • 0
    G

    beautiful solution!


  • 0
    C

    How beautiful solution, beats 98% c++ submissions. I think I need to investigate the differences between unordered_map and unordered_multiset.


Log in to reply
 

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