Skip to content

Instantly share code, notes, and snippets.

@divmgl
Created March 23, 2017 20:37
Show Gist options
  • Save divmgl/6d4a108b9264d36f24bcfac81131a32c to your computer and use it in GitHub Desktop.
Save divmgl/6d4a108b9264d36f24bcfac81131a32c to your computer and use it in GitHub Desktop.
Codility.com BinaryGap 100% in C
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