Number Complement – Leetcode

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.
  1. The given integer is guaranteed to fit within the range of a 32-bit signed integer.
  2. You could assume no leading zero bit in the integer’s binary representation.
Example 1:

Example 2:



If you have still not understood the solution, the below debugging will help you understand better.

Debug the solution


You may also like Java interview questions


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: