leetcode-461. 汉明距离

class Solution { public: int hammingDistance(int x, int y) { int res = x^y; // 异或不同为结果为1 unsigned int flag = 1; int count = 0; while(flag){ if(flag&res) // 判断哪一位为1 count++; flag = flag<<1; } return count; } };

class Solution { public: int hammingDistance(int x, int y) { int res = x^y; // 异或不同为结果为1 unsigned int flag = 1; int count = 0; while(flag){ if(flag&res) // 判断哪一位为1 count++; flag = flag<<1; } return count; } };