476. Number Complement 數字補數
❀ Origin
Problem
Given a positive integer, output its complement number.
The complement strategy is to flip the bits of its binary representation.
Note
- The given integer is guaranteed to fit within the range of a 32-bit signed integer.
- You could assume no leading zero bit in the integer’s binary representation.
Example 1
1 | Input: 5 |
Example 2
1 | Input: 1 |
❀ 翻譯
問題
給定一個正整數, 輸出其補數.
補數的定義是翻轉其二進制數的每個代表位元.
注意
- 給定的整數保證符合在 32 位元有號數的範圍內.
- 你可以在整數的二進制表示裡假設其沒有前面的 0 位元.
❀ Solution
JavaScript
1 | /** |