Created
October 16, 2016 23:54
-
-
Save zmarvel/ebf593435aabdcae4f4cd85addaefda0 to your computer and use it in GitHub Desktop.
Leetcode 190 solution.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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