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; } };
标签:count,int,res,461,unsigned,flag,汉明,leetcode 来源: https://www.cnblogs.com/ymec/p/15057832.html