Complement of Base 10 Integer

Easy

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 = 5
Output:2
Explanation:

5 is 101, complement is 010 = 2.

Input:n = 7
Output:0
Explanation:

7 is 111 in binary. The complement is 000 = 0.

Input:n = 1
Output:0
Explanation:

1 is 1 in binary, complement is 0 = 0. This demonstrates the smallest positive input case.

Constraints

  • 0 ≤ n < 10⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!