My LeetCode grinding. Trying to do a problem a day.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

12345678910111213141516171819202122232425
  1. Given a positive integer num, output its complement number. The complement strategy is to flip the bits of its binary representation.
  2. Example 1:
  3. Input: num = 5
  4. Output: 2
  5. Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
  6. Example 2:
  7. Input: num = 1
  8. Output: 0
  9. Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
  10. Constraints:
  11. The given integer num is guaranteed to fit within the range of a 32-bit signed integer.
  12. num >= 1
  13. You could assume no leading zero bit in the integer’s binary representation.
  14. This question is the same as 1009: https://leetcode.com/problems/complement-of-base-10-integer/