LeetCode #476

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

Pseudo code

  1. parse integer to binary
  2. store every digit into to an array
  3. invert every item in array to the opposite
  4. merge the inverted array
  5. parse back to integer


See the Pen #476 Number Complement by Cherry Wang (@chryw) on CodePen.