Skip to content

Instantly share code, notes, and snippets.

@zmarvel
Created October 16, 2016 23:54
Show Gist options
  • Save zmarvel/ebf593435aabdcae4f4cd85addaefda0 to your computer and use it in GitHub Desktop.
Save zmarvel/ebf593435aabdcae4f4cd85addaefda0 to your computer and use it in GitHub Desktop.
Leetcode 190 solution.
# Given a 32-bit decimal number, convert it to binary, reverse it, then print
# the reversed version in decimal.
def solution(n):
result = 0
for i in range(32):
result |= ((n >> i) & 1) << (31 - i)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment