Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created July 21, 2018 11:27
Show Gist options
  • Save luojiyin1987/62623e1aefaa2304545cc7822759ede9 to your computer and use it in GitHub Desktop.
Save luojiyin1987/62623e1aefaa2304545cc7822759ede9 to your computer and use it in GitHub Desktop.
Binary Gap
def binaryGap(self, N):
"""
:type N: int
:rtype: int
"""
result = 0
last = None
for i in range(32):
if (N >> i) & 1:
if last is not None:
result = max(result, i-last)
last = i
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment