Minimum Bit Flips to Convert Number
给两个数字, 求两个数字中不相同的bit的个数.
先xor, 然后counting bit.
class Solution {
public int minBitFlips(int start, int goal) {
int x = start ^ goal;
int res = 0;
for (res = 0; x != 0; x >>= 1)
{
res += x & 1;
}
return res;
}
}