int main()
{
const int n =7;
int A[n]={1,1,4,3,2,3,2};
int i = 0, j = 0;
int ans = 0;
for(i = 0;i < n;i++)
{
for(j = 0;j < n;j++)
{
if(i == j)
continue;//同一个数不用比较
else if(A[i] == A[j])
break; //终止内层for循环
else continue;//既不是同一个数,又不相等,只能继续找下一个
}
if(j == n)
cout<<A[i]<<endl;//所有的都找完了没发现相同的 说明是单个的
}
}
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?