3 Line C++ O(1) Space O(N) Time


  • 1
    F
    struct Solution {
        vector<int> singleNumber(vector<int>& nums) {
            int a = 0, b = 0, s = accumulate(nums.begin(), nums.end(), 0, bit_xor<int>());
            for (auto n : nums) n & s & -s ? a ^= n: b ^= n;
            return vector<int>{a, b};
        }
    };

Log in to reply
 

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