Given 2*n + 1
numbers, every numbers occurs twice except one, find it.
Example
Given [1,2,2,1,3,4,3]
, return 4
Challenge
One-pass, constant extra space.
LeetCode上的原题,请参见我之前的博客Single Number。
class Solution { public: int singleNumber(vector<int>& nums) { int res = 0; for (auto num : nums) res ^= num; return res; } };