int findComplement(int num) {
/*int count = 0;
if (num == 1) return 0;
while (num)
{
num &= (num - 1);
count++;
}
return count;*/
int i,flag = 0;
for (i = 31; i >= 0; i--)
{
if ((num & (1 << i)) || flag)
{
flag |= 1 << i;
}
}
return num^flag;
}
void main() {
printf("%d" ,findComplement(8));
system("pause");
}
Number Complement
最新推荐文章于 2021-10-18 01:24:54 发布