Java - 10ms - bit manipulate


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

Log in to reply
 

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