@@ -0,0 +1,1313 @@
+package com.freetymekiyan.algorithms.level.easy;%0A%0A/**%0A * 461. Hamming Distance%0A * %3Cp%3E%0A * The Hamming distance between two integers is the number of positions at which the corresponding bits are different.%0A * %3Cp%3E%0A * Given two integers x and y, calculate the Hamming distance.%0A * %3Cp%3E%0A * Note:%0A * 0 %E2%89%A4 x, y %3C 231.%0A * %3Cp%3E%0A * Example:%0A * %3Cp%3E%0A * Input: x = 1, y = 4%0A * %3Cp%3E%0A * Output: 2%0A * %3Cp%3E%0A * Explanation:%0A * %7C 1   (0 0 0 1)%0A * %7C 4   (0 1 0 0)%0A * %7C        %E2%86%91   %E2%86%91%0A * %3Cp%3E%0A * The above arrows point to positions where the corresponding bits are different.%0A * %3Cp%3E%0A * Related Topics: Bit Manipulation%0A * Similar Questions: (E) Number of 1 Bits, (M) Total Hamming Distance%0A */%0Apublic class HammingDistance %7B%0A%0A    /**%0A     * Bit Manipulation.%0A     * By def., hamming distance is the number of positions where%0A     * the corresponding bits are different.%0A     * XOR can generate a result where different bits produce 1, same bits produce 0.%0A     * This can distinguish different bits from same bits.%0A     * Then we just need to count the number of 1s after XOR.%0A     * One-liner: Integer.bitCount(x %5E y);%0A     */%0A    public int hammingDistance(int x, int y) %7B%0A        int xor = x %5E y;%0A        int d = 0;%0A        while (xor != 0) %7B%0A            if ((xor & 1) == 1) d++;%0A            xor %3E%3E= 1;%0A        %7D%0A        return d;%0A    %7D%0A%7D

add 461. Hamming Distance