LeetCode solutions

3428. Find the XOR of Numbers Which Appear Twice

My accepted C++ solution to LeetCode problem 3428, Find the XOR of Numbers Which Appear Twice, running in 0ms.

  • Difficulty: Easy
  • C++
  • Runtime 0ms
  • Memory 27.1MB

Read the problem on LeetCode View on GitHub

C++

Accepted on LeetCode — runtime 0ms, memory 27.1MB, accepted 2025-12-27.

cpp
class Solution {
    public:
    int duplicateNumbersXOR(vector<int>& nums) {
        long long seen = 0;
        int result = 0;
        for (int n : nums) {
            if (seen & (1LL << n)) result ^= n;
            seen |= (1LL << n);
        }
        return result;
    }
};

Source