cpp solution


  • -1
    V

    class Solution {
    public:
    int hammingDistance(int x, int y) {
    unsigned int hamming=0;
    unsigned diffbits=x^y;
    while(diffbits)
    {
    hamming++;
    diffbits=(diffbits)&(diffbits-1);
    }
    return hamming;
    }
    };


Log in to reply
 

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