Last active
April 8, 2017 09:48
-
-
Save divmgl/766af75c2c6abe24d457edbc888cd45a to your computer and use it in GitHub Desktop.
Codility.com BinaryGap 100%
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 solution(N): | |
max = 0 | |
bits = 0 | |
bin = "{0:b}".format(N) | |
for c in bin: | |
if c == "0": | |
bits += 1 | |
if c == "1": | |
if max < bits: | |
max = bits | |
bits = 0 | |
return max |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The solution in C: