Number Complement

Easy

The complement of an integer flips every bit of its binary representation (ignoring leading zeros).

Given num, return its complement.

Example 1

findComplement()
Input
num = 5
Output
2

Why

101 → 010

Example 2

findComplement()
Input
num = 1
Output
0
Constraints
1 <= num < 2^31

Topics

Bit Manipulation

Implement findComplement in the editor and return the answer — printing it is never graded.