Leetcode 136 Single Number
#include <vector>
using namespace std;
class Solution {
public:
int singleNumber(vector<int>& nums) {
//异或操作,相同元素异或为0,a^b = b^a,a^0 = a;
int single = 0;
for (int i = 0; i < nums.size(); i++){
single ^= nums[i];
}
//for(auto a : nums) single ^= a;//c++11新特性
return single;
}
};