Skip to content

Instantly share code, notes, and snippets.

@mhewedy
Created April 21, 2018 18:26
Show Gist options
  • Select an option

  • Save mhewedy/f8c38ff14554080bd983089ca27495a0 to your computer and use it in GitHub Desktop.

Select an option

Save mhewedy/f8c38ff14554080bd983089ca27495a0 to your computer and use it in GitHub Desktop.
Codility binary gap solution
private static int gap(int N) {
int max = 0;
int counter = -1;
while (N != 0) {
if ((N & 1) == 1) {
if (counter > max) {
max = counter;
}
counter = 0;
} else if (counter >= 0) {
counter++;
}
N >>>= 1;
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment