#include <iostream> using namespace std; int singleNumber1(int a[],int n) { int result=0; for (int i = 0; i < 32; i++) { int sum=0; for (int j = 0; j < n; j++) { sum+=(a[j]>>i)&1; } result|=(sum%3)<<i; } return result; } int singleNumber2(int A[], int n) { int ones = 0, twos = 0, threes = 0; for (int i = 0; i < n; ++i) { twos |= (ones & A[i]); ones ^= A[i]; threes = ~(ones & twos); ones &= threes; twos &= threes; } return ones; } int singleNumber3(int A[],int n) { int a = 0; int b = 0; for (int i = 0; i < n; i++) { b = (b ^ A[i]) & ~a; a = (a ^ A[i]) & ~b; } return b; } int main() { int a[10]={2,2,2,4,4,4,6,7,7,7}; int ans=singleNumber1(a,10); cout<<"the ans is "<<ans<<endl; int ans2=singleNumber2(a,10); cout<<"the ans is "<<ans2<<endl; int ans3=singleNumber3(a,10); cout<<"the ans3 is "<<ans3<<endl; return 0; }