看下面题解都太复杂了,写个简单的C++
数组中只出现一次的数字
https://www.nowcoder.com/questionTerminal/e02fdb54d7524710a7d664d082bb7811?answerType=1&f=discussion
class Solution { public: void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { int ans = 0; for(int d: data) ans ^= d; *num1 = ans; *num2 = ans; int tmp = ans &(~ans+1); //取最右边1 for(int d: data){ if(tmp&d) *num1 ^= d; else *num2 ^= d; } } };