Skip to content

Instantly share code, notes, and snippets.

@arpi-r
Created October 22, 2018 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arpi-r/0c24e13d9c3aeae6fd38c3462e5f2b44 to your computer and use it in GitHub Desktop.
Save arpi-r/0c24e13d9c3aeae6fd38c3462e5f2b44 to your computer and use it in GitHub Desktop.
WebClub codebuddy week3
int Solution::singleNumber(const vector<int> &A) {
vector<int> n(32,0);
int t = 1;
for(int i = 1; i < 32 ; i++){
int one = 0;
if( i==1 ){
t = 1;
}
else{
t = t<<1;
}
for(int j = 0 ; j < A.size() ; j++){
int x = t&A[j];
if(x!=0)
one = one + 1;
}
n[i-1]=one%3;
}
int num=0,b=1;
for(int i=0;i<31;i++){
num = num + (n[i]*b);
b = b * 2;
}
return num;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment