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?
解题思路:
普通程序员方法
用一个hashmap数数,再遍历一次即可。
int singleNumber(int A[], int n)
{
unordered_map<int, int> count;
for(int i = 0; i < n; i++)
count[A[i]]++;
for(int i = 0; i < n; i++)
{
if(count[A[i]] != 2)
return A[i];
}
//error
return 0;
}