C# Solution (Hamming Distance)


  • 0
    A
     public int HammingDistance(int x, int y)
                {
                    int count = 0;
                    int XORedValue = x ^ y;
                    do
                    {
                        if (XORedValue % 2 != 0)
                            count++;
                       XORedValue = XORedValue >> 1;                    
                    } while (XORedValue != 0);
                    
                 return count;
                }
    
    

Log in to reply
 

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