Created
March 8, 2023 13:12
-
-
Save kanelv/1e4ca83140c24c25d36d63d9ad09ca19 to your computer and use it in GitHub Desktop.
BinaryGap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const solution = (N) => { | |
const binary = N.toString(2); | |
let count = 0; | |
let answer = 0; | |
for(let b of binary) { | |
if (b === "0") { | |
count++ | |
} else { | |
if (count > answer) { | |
answer = count; | |
} | |
count = 0 | |
} | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment