Hamming distance c++ solution


  • 0
    D

    Time complexity is O(n) but simple

    int hammingDistance(int x, int y)
    {
        int ret=0;
        for(int i=0; i<32; i++)
        {
            ret+=((x>>i)&1)^((y>>i)&1);
         }
        return ret;
    }
    

Log in to reply
 

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