C/C++ solution: 4 lines, 13 operations


  • 0
    I
    int hammingDistance(int x, int y)
    {
        x ^= y;
        x = x - ((x >> 1) & 0x55555555);
        x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
        return (((x + (x >> 4) & 0xF0F0F0F) * 0x1010101) >> 24);
    }
    

Log in to reply
 

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