您的位置:首页 > 其它

leetCode #136 Single number

2015-08-20 00:10 204 查看
题目:一个数组中,有一个数只出现了一次,其余数都出现2次,求找这个只出现一次的数

分析:a xor 0 = a; a xor a =0; so...

答案:

class Solution {
public:
int singleNumber(vector<int>& nums) {
int res = 0;
for (int i = 0; i< nums.size(); i++){
res ^= nums[i];
}
return res;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: