You can use a hash map to record the frequencys. Or you can use bit operation.
x ^ x = 0. So the only left is the one.
1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 int result = 0; 5 for (int i = 0; i < n; i++) { 6 x ^= A[i]; 7 } 8 return result; 9 }10 };