package leetcode;

/**
 * https://leetcode.com/problems/hamming-distance/
 */
public class Problem461 {
    public int hammingDistance(int x, int y) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem461 prob = new Problem461();
        System.out.println(prob.hammingDistance(1, 4)); // 2
    }
}

package leetcode;

/**
 * https://leetcode.com/problems/hamming-distance/
 */
public class Problem461 {
    public int hammingDistance(int x, int y) {
        int xor = x ^ y;
        int result = 0;
        while (xor > 0) {
            result += xor & 1;
            xor >>= 1;
        }
        return result;
    }
}

Solve problem 461