LeetCode’s Number Complement Explained

Saloni Kaur
2 min readOct 5, 2020

Given a positive integer num, output its complement number. The complement strategy is to flip the bits of its binary representation.

Please try on your own before reading on.

Before solving this problem, we need to understand a few concepts in bitwise manipulation.

XOR (^) Finding the complement of a number:

--

--