Java solution


  • 0
    D
    public class Solution {
        public int hammingDistance(int x, int y) {
            int z = x ^ y;
            int ret = 0;
            while (z != 0) {
                ret++;
                z = z & (z - 1);
            }
            return ret;
        }
    }
    

Log in to reply
 

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