Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 26, 2018 03:32
Show Gist options
  • Save clarkdo/890da771354b48b6b27ce99cc36b22e3 to your computer and use it in GitHub Desktop.
Save clarkdo/890da771354b48b6b27ce99cc36b22e3 to your computer and use it in GitHub Desktop.
class Solution {
public int solution(int N) {
int current = N;
int max = 0;
int currentGap = 0;
boolean start = false;
while (current / 2 != 0) {
if (current % 2 != 0) {
max = currentGap > max ? currentGap : max;
currentGap = 0;
start = true;
} else if (start) {
currentGap++;
}
current = current / 2;
}
if (currentGap > max) {
max = currentGap;
}
return max;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment