1 class Solution {
 2 public:
 3     int singleNumber(int A[], int n) {
 4         int ones = 0, twos = 0, threes = 0;
 5         for (int i = 0; i < n; i++) {
 6             twos |= (ones & A[i]);
 7             ones ^= A[i];
 8             threes = ~(ones & twos);
 9             ones &= threes;
10             twos &= threes;
11         }
12         return ones;
13     }
14 };

 

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