Number Complement

Easy · Bit Manipulation · about 5 minutes

Asked at Google, Amazon, Microsoft, Apple.

The complement of a positive integer flips every bit of its binary representation (without leading zeros), e.g. 5 = 101 → 010 = 2. Return the complement of num.