Created
October 22, 2018 14:32
-
-
Save arpi-r/0c24e13d9c3aeae6fd38c3462e5f2b44 to your computer and use it in GitHub Desktop.
WebClub codebuddy week3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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