Skip to content

Instantly share code, notes, and snippets.

@justscribner
Created January 17, 2018 19:56
Show Gist options
  • Select an option

  • Save justscribner/c1488cc8b6b1b09274af49090d38e956 to your computer and use it in GitHub Desktop.

Select an option

Save justscribner/c1488cc8b6b1b09274af49090d38e956 to your computer and use it in GitHub Desktop.
Binary Gap Solution
function solution(N) {
var binary = Number(N).toString(2);
var max = 0;
var curr = 0;
for(var i = 0; i < binary.length; i++) {
if (binary[i] === '0') {
curr++
} else {
max = Math.max(curr, max);
curr = 0;
}
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment