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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 27.1MB, accepted 2025-12-27.
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;
}
};