Skip to content

Instantly share code, notes, and snippets.

@hungneox
Last active January 30, 2021 00:20
Show Gist options
  • Save hungneox/20f7780034d09fc5cf753de8649933be to your computer and use it in GitHub Desktop.
Save hungneox/20f7780034d09fc5cf753de8649933be to your computer and use it in GitHub Desktop.
Codility BinaryGap - Python solution
def solution(N):
# write your code in Python 3.6
meet_one = False
count = 0
keep = []
while N:
if meet_one and N & 1 == 0:
count+=1
if N & 1:
meet_one = True
keep.append(count)
count = 0
N >>=1
return max(keep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment