We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
example
Input: x = 1, y = 4 Output: 2 Explanation: 1 (0 0 0 1) 4 (0 1 0 0) ↑ ↑
answer
//主要就是几个位操作符 var hammingDistance = function(x, y) { var a = x ^ y; var count = 0 ; while ( a ) { if (a & 1){ count ++; } a = a >> 1; } return count; };
Input: 5 Output: 2 Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
var findComplement = function(num) { var l = num.toString(2).length; var _num =Math.pow(2,l)-1; return num^_num }; var findComplement = function(num) { var mask = ~0; while (mask & num) { mask = mask << 1; } return ~(mask ^ num); };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hamming Distance
example
answer
Number Complement
example
answer
The text was updated successfully, but these errors were encountered: