The complement of an integer is what you get by turning every 0 into a 1 and every 1 into a 0 in its binary form, with no leading zeros. For example, 5 is "101" in binary, so its complement is "010", which is 2. Given an integer n, return its complement.
The complement of an integer is what you get by turning every 0 into a 1 and every 1 into a 0 in its binary form, with no leading zeros. For example, 5 is "101" in binary, so its complement is "010", which is 2. Given an integer n, return its complement.
Example 1:
Input: {"n":5}
Output: 2
Constraints:
0≤n<109
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":5}
n = 5 is 101 in binary. Read its bits from the bottom, write each one flipped into result, and stop when n runs out of bits.