Single Number II

Code:

 

class Solution {
public:
    int singleNumber(int A[], int n) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
        int res = 0;
        int bit,i,j;
        for(i=0;i<32;i++){
            for(j=0, bit=0;j<n;j++){
                if((A[j]>>i)&1==1)
                    bit = (bit+1)%3;
            }
                if(bit!=0)
                    bit = 1;
                res = res | (bit<<i);
        }
        return res;
    }
};

 

posted @ 2013-10-23 02:40  WinsCoder  阅读(93)  评论(0编辑  收藏  举报