题解 | #整数转化#
整数转化
http://www.nowcoder.com/practice/c7df20a5a39e4357aecc1071e7fd523c
class Transform {
public:
int calcCost(int A, int B) {
// A 和 B 异或后统计结果中的1的个数
int temp = A ^ B;
int counter = 0;
while(temp > 0)
{
if(temp & 1 == 1) counter++;
temp = temp >> 1;
}
return counter;
}
};