Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
x ^ x = 0
0 ^ x = x
class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = 0;
for (auto& x : nums) {
res ^= x;
}
return res;
}
};