MCPcopy Create free account
hub / github.com/Ayush7614/Daily-Coding-DS-ALGO-Practice / hammingDistance

Method hammingDistance

Leetcode/Java/Hamming.java:4–16  ·  view source on GitHub ↗
(int x, int y)

Source from the content-addressed store, hash-verified

2class Hamming
3{
4static int hammingDistance(int x, int y)
5{
6 int n = x ^ y;
7 int setBits = 0;
8
9 while (n > 0)
10 {
11 setBits += n & 1;
12 n >>= 1;
13 }
14
15 return setBits;
16}
17public static void main(String[] args)
18{
19 Scanner sc = new Scanner(System.in);

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected