题目描述
一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。
1 class Solution { 2 public: 3 void FindNumsAppearOnce(vector<int> data,int* num1,int *num2) { 4 int diff=0; 5 for(int i=0; i<data.size(); ++i) 6 diff ^= data[i]; 7 diff &= -diff; 8 for(int i=0; i<data.size(); ++i) 9 if((diff & data[i]) == 0) // == 优先级高 10 num1[0] ^= data[i]; 11 else 12 num2[0] ^= data[i]; 13 } 14 };