LeetCode 136. Single Number
Solution1:我的答案
还好异或的性质没记错,还好,还好
class Solution {
public:
int singleNumber(vector<int>& nums) {
if (nums.size() == 1)
return nums[0];
int res = nums[0];
for (int i = 1; i < nums.size(); i++)
res = res^nums[i];
return res;
}
};