首页 > 代码库 > [LintCode] Single Number 单独的数字

[LintCode] Single Number 单独的数字

 

Given 2*n + 1 numbers, every numbers occurs twice except one, find it.

Have you met this question in a real interview? 
Yes
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;    }};

 

[LintCode] Single Number 单独的数字