Created
September 4, 2020 00:50
-
-
Save riyafa/cb5dd09710438ca24b34b07efa7df45e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class HammingDistance { | |
public int hammingDistance(int x, int y) { | |
int res = x ^ y; | |
int count = 0; | |
while (res > 0) { | |
res = res & (res - 1); | |
count++; | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment