190-Reverse-Bits

Sat 17 May 2025

https://leetcode.com/problems/reverse-bits

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def reverseBits(self, n: int) -> int:
    ans = 0

    for i in range(32):
      if n >> i & 1:
        ans |= 1 << 31 - i

    return ans
new Solution().reverseBits()

Score: 5

Category: leetcode