Created
January 17, 2018 19:56
-
-
Save justscribner/c1488cc8b6b1b09274af49090d38e956 to your computer and use it in GitHub Desktop.
Binary Gap Solution
This file contains hidden or 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
| 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