int main()
{
char arr[] = { 1,2,3,4,5,7,5,1,2,3,4 };
int sz = sizeof(arr) / sizeof(arr[0]);
int i,ret = 0;
//0^a=a,a^b^a=b,a^a=0,异或满足交换规律,相同为0,反之为1;
for (i = 0; i < sz; i++)
{
ret = ret ^ arr[i];
}
printf("单身狗是 %d", ret);
return 0;
}
int main()
{
char arr[] = { 1,2,3,4,5,7,5,1,2,3,4 };
int sz = sizeof(arr) / sizeof(arr[0]);
//暴力求解
int i = 0;
for (i = 0; i < sz; i++)
{
int j = 0;
int count = 0;//计数器
for (j = 0; j < sz; j++)
{
if (arr[i] == arr[j])
{
count++;//每个元素会和自己比一次,然后和数组内相同的元素
//再比较一次,重复了,count = 2,没重复,count = 1
}
}
if (count == 1)
{
printf("单身狗是 %d", arr[i]);
break;
}
}
return 0;
}