题目:136. 只出现一次的数字
思路:两个相同的数进行位运算的结果为0,那么将所有元素进行位运算,最后的结果自然就是单着的数了。
class Solution {
public:
int singleNumber(vector<int>& nums) {
int tmp=0;
for(auto x:nums) tmp^=x;
return tmp;
}
};
思路:两个相同的数进行位运算的结果为0,那么将所有元素进行位运算,最后的结果自然就是单着的数了。
class Solution {
public:
int singleNumber(vector<int>& nums) {
int tmp=0;
for(auto x:nums) tmp^=x;
return tmp;
}
};