题目:

颠倒二进制位:颠倒给定的 32 位无符号整数的二进制位。

思路:

思路较简单。

程序:

class Solution:
    def reverseBits(self, n: int) -> int:
        if not n:
            return 0
        result = 0
        for index in range(31, -1, -1):
            result += (n & 1) << index
            n = n >> 1
        return result

  

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2022-01-08
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-09-03
相关资源
相似解决方案