use c++


  • 0
    Q

    class Solution
    {
    public:
    int hammingDistance(int x, int y)
    {
    int dis = 0,bit;
    char check;
    bit = x^y;
    while (bit)
    {
    check = (1 & bit) + '0';
    if (check == '1')
    dis++;
    bit >>= 1;
    }

    	return dis;
       }
    

    };


Log in to reply
 

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