Description
The complement of an integer is the integer you get when you flip all the 0s to 1s and all the 1s to 0s in its binary representation. Given n, return its complement.
Examples
Input:
n = 5Output:
2Explanation:
5 is 101, complement is 010 = 2.
Input:
n = 7Output:
0Explanation:
7 is 111 in binary. The complement is 000 = 0.
Input:
n = 1Output:
0Explanation:
1 is 1 in binary, complement is 0 = 0. This demonstrates the smallest positive input case.
Constraints
- •
0 ≤ n < 10⁹