Last active
January 30, 2021 00:20
-
-
Save hungneox/20f7780034d09fc5cf753de8649933be to your computer and use it in GitHub Desktop.
Codility BinaryGap - Python solution
This file contains hidden or 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 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