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; } };
本文转自博客园Grandyang的博客,原文链接:单独的数字[LintCode] Single Number ,如需转载请自行联系原博主。