LeetCode-136
作者:互联网
非常有意思,通过位运算来解决,A^A = 0,并且有交换律,A^B^A = A^A^B
代码:
class Solution {
public:
int singleNumber(vector<int>& nums) {
int a = 0, i;
for (i = 0; i < nums.size(); ++i)
{
a = a ^ nums[i];
}
return a;
}
};
标签:交换律,return,nums,int,class,vector,136,LeetCode 来源: https://blog.csdn.net/xcppp0518/article/details/112426972