Skip to content

Instantly share code, notes, and snippets.

@allenhwkim
Created July 2, 2022 19:57
Show Gist options
  • Save allenhwkim/2aacd7bf80f47e7b58aa6f5b92a77270 to your computer and use it in GitHub Desktop.
Save allenhwkim/2aacd7bf80f47e7b58aa6f5b92a77270 to your computer and use it in GitHub Desktop.
Binary Gap
function solution(N) {
const binString = N.toString(2);
const matches = binString.replace(/[0]+$/, '').match(/0+/g);
return (matches || []).reduce( (acc, cur) => Math.max(acc, cur.length), 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment