Java easy to understand

  • 0

    First I xor the two numbers. Then I count the number of one bits in that number.

    public class Solution {
        public int hammingDistance(int x, int y) {
            int z = x ^ y;
            int count = 0;
                if(z%2 == 1)
                z /= 2;
            return count;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.