Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python bit #11

Closed
huashiyiqike opened this issue May 5, 2015 · 0 comments
Closed

python bit #11

huashiyiqike opened this issue May 5, 2015 · 0 comments

Comments

@huashiyiqike
Copy link

An easy solution for Single number I and II is based on 32 bit presentation which python do not naturally support. Is there a way to transform this to python? Thanks

class Solution {
public:
int singleNumber(vector& nums) {
int digits[32]={0};
for( int k=0;k<nums.size();k++)
for ( int i =0;i<32;i++)
if ( nums[k]>>i&1)
digits[i]+=1;
int res=0;
for ( int i =0;i<32;i++)
res+=(digits[i]%2)<<i;
return res;
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants