Created
September 21, 2016 12:31
-
-
Save kdhfred/7662b2596651e9099f87035a64953b21 to your computer and use it in GitHub Desktop.
Codility BinaryGap
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
def solution(N): | |
bin_N = bin(N)[2:] | |
bin_gaps = [ len(x) for x in bin_N.split('1') ] | |
if not bin_N[-1] == '1': | |
bin_gaps.pop() | |
return max(bin_gaps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment