Easily Understanable C++ Solution


  • 0
    G
    class Solution {
    public:
        int hammingDistance(int x, int y) {
            int res = 0;
            for (int i = 0; i < 32; ++i) {
                if ((x & (1 << i)) ^ (y & (1 << i))) {
                    ++res;
                }
            }
            return res;
        }
    };

Log in to reply
 

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