Skip to content

Instantly share code, notes, and snippets.

@RohitK09
Created February 3, 2017 04:23
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 RohitK09/ba1c873cb6f0921b239ae4c95260a312 to your computer and use it in GitHub Desktop.
Save RohitK09/ba1c873cb6f0921b239ae4c95260a312 to your computer and use it in GitHub Desktop.
Hamming Distance in JS
/**
* @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