void FindNumsAppearOnce(vector<int> data, int* num1, int *num2)
{
if (data.size()<2)
{
return;
}
int N(data[0]);
for (auto i = 1; i < data.size();++i)
{
N = N^data[i];
}
int k(0);
while (!((N>>k)&1))
{
k++;
}
int Ncopy(N);
for (auto i = 0; i < data.size();++i)
{
if ((data[i]>>k)&1)
{
N = N^data[i];
}
}
*num1 = N;
*num2 = N^Ncopy;
}
【剑指offer】题40:数组中只出现一次的数字
最新推荐文章于 2022-03-13 14:30:09 发布