Skip to content

Instantly share code, notes, and snippets.

@riyafa
Created September 4, 2020 00:50
Show Gist options
  • Save riyafa/cb5dd09710438ca24b34b07efa7df45e to your computer and use it in GitHub Desktop.
Save riyafa/cb5dd09710438ca24b34b07efa7df45e to your computer and use it in GitHub Desktop.
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