Skip to content

Instantly share code, notes, and snippets.

@divmgl
Created March 23, 2017 20:37
Show Gist options
  • Select an option

  • Save divmgl/6d4a108b9264d36f24bcfac81131a32c to your computer and use it in GitHub Desktop.

Select an option

Save divmgl/6d4a108b9264d36f24bcfac81131a32c to your computer and use it in GitHub Desktop.

Revisions

  1. divmgl created this gist Mar 23, 2017.
    21 changes: 21 additions & 0 deletions binarygap.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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;
    }