Created
March 23, 2017 20:37
-
-
Save divmgl/6d4a108b9264d36f24bcfac81131a32c to your computer and use it in GitHub Desktop.
Codility.com BinaryGap 100% in C
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
long bits = 0; | |
long max = 0; | |
void binary(long N) { | |
if (N > 1) { | |
binary(N / 2); | |
} | |
if (N % 2 == 0) { | |
bits += 1; | |
return; | |
} | |
if (max < bits) { | |
max = bits; | |
} | |
bits = 0; | |
} | |
long solution(long N) { | |
binary(N); | |
return max; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment