C constant time solution


  • 0
    V
    int hammingDistance(int x, int y) {
        int x1 = x;
        int y1 = y;
        int diff = x ^ y;
        diff = (diff - ((diff >> 1) & 033333333333) - ((diff >> 2) & 011111111111));
        return ((diff + (diff >> 3)) & 030707070707) % 63;
    }
    

Log in to reply
 

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