Skip to content

Instantly share code, notes, and snippets.

@wenweixu
Created September 3, 2019 03:29
Show Gist options
  • Save wenweixu/072fcfce212ad900a0316a9ebf508bc0 to your computer and use it in GitHub Desktop.
Save wenweixu/072fcfce212ad900a0316a9ebf508bc0 to your computer and use it in GitHub Desktop.
Hackerrank Flipping_bits python solution
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