Skip to content

Instantly share code, notes, and snippets.

@munguial
Created July 15, 2020 06:30
Show Gist options
  • Save munguial/e96ea5b40c3b692311dc372662f960d8 to your computer and use it in GitHub Desktop.
Save munguial/e96ea5b40c3b692311dc372662f960d8 to your computer and use it in GitHub Desktop.
July - Day 12 - Reverse Bits
# https://leetcode.com/explore/challenge/card/july-leetcoding-challenge/545/week-2-july-8th-july-14th/3388/
class Solution:
def reverseBits(self, n: int) -> int:
res = 0
i = 0
while i < 32:
if (1 << i) & n:
res |= 1 << (31 - i)
i += 1
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment