Created
February 3, 2017 04:23
-
-
Save RohitK09/ba1c873cb6f0921b239ae4c95260a312 to your computer and use it in GitHub Desktop.
Hamming Distance in JS
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
/** | |
* @param {number} x | |
* @param {number} y | |
* @return {number} | |
*/ | |
var hammingDistance = function(x, y) { | |
var resultStr =( x^y); | |
let count =0; | |
while(resultStr>0){ | |
resultStr =(resultStr&resultStr-1) ; | |
count++; | |
} | |
return count; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment