# [476. Number Complement](https://leetcode.com/problems/number-complement/description/)
# 思路
先将num的bit全部翻转，再看num有多少前导0，然后用一个合适的mask对之前的翻转结果进行与操作即可。
# C++
``` C++
class Solution {
public:
    int findComplement(int num) {
        if(num == 0) return 1;
        int i, res = ~num, mask=0xffffffff;
        while(mask & num) mask <<= 1;
        return res & ~mask;
    }
};
```
