Problem
The complement of a number flips every bit of its binary form (without leading zeros): 1s become 0s and 0s become 1s. For example 5 is 101, whose complement is 010, which is 2. Given n, return its complement.
Example 1
- Input
- n = 5
- Output
- 2
- Why
- 101 → 010
Example 2
- Input
- n = 7
- Output
- 0
- Why
- 111 → 000
Example 3
- Input
- n = 10
- Output
- 5
- Why
- 1010 → 0101
Example 4
- Input
- n = 0
- Output
- 1
- Why
- 0 → 1
Constraints
0 <= n < 10^9