Created
September 3, 2019 03:29
-
-
Save wenweixu/072fcfce212ad900a0316a9ebf508bc0 to your computer and use it in GitHub Desktop.
Hackerrank Flipping_bits python 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
def flippingBits(n): | |
result = 0 | |
for i in range(31,-1,-1): | |
if n//(2**i) == 1: | |
n = n - 2**i | |
x = 0 | |
else: | |
x = 1 | |
result += 2**i * x | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment