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 };

 

posted on 2015-03-23 15:05  keepshuatishuati  阅读(78)  评论(0编辑  收藏  举报