Leetcode 461 Solution

This article provides solution to leetcode question 461 (hamming-distance)

https://leetcode.com/problems/hamming-distance

Solution

class Solution {
public:
    int hammingDistance(int x, int y) {
        int z = x ^ y;

        int cnt = 0;

        while (z)
        {
            z = z & (z - 1);
            cnt++;
        }

        return cnt;
    }
};