1 class Solution {
 2 public:
 3     int singleNumber(int A[], int n) {
 4         // Note: The Solution object is instantiated only once and is reused by each test case.
 5         if (n == 0) return 0;
 6         
 7         int bit[32];
 8         int result = 0;
 9         
10         for (int i = 0; i < 32; i++){
11             
12             bit[i] = 0;
13             for (int j = 0; j < n; j++){
14                 
15                 if ((A[j] >> i) & 1) bit[i] = (bit[i] + 1) % 3;
16             }
17             result += (bit[i]<<i);
18         }
19         return result;
20     }
21 };

 

posted on 2013-10-27 03:44  tanghulu321  阅读(144)  评论(0编辑  收藏  举报