LCR 177. 撞色搭配
LCR 177. 撞色搭配
迷你游戏之寻找两个单身狗
int* sockCollocation(int* sockets, int socketsSize, int* returnSize)
{
int* arr = (int*)malloc(2 * sizeof(int));
int ret = 0;
for (int i = 0; i < socketsSize; i++)
{
ret ^= sockets[i];
}
int pos = 0;
for (int i = 0; i < 32; i++)
{
if (ret & (1 << i))
{
pos = i;
break;
}
}
int m = 0;
for (int i = 0; i < socketsSize; i++)
{
if (sockets[i] & (1 << pos))
{
m ^= sockets[i];
}
}
int n = ret ^ m;
arr[0] = m;
arr[1] = n;
*returnSize = 2;
return arr;
}