Skip to content

Instantly share code, notes, and snippets.

@kdhfred
Created September 21, 2016 12:31
Show Gist options
  • Save kdhfred/7662b2596651e9099f87035a64953b21 to your computer and use it in GitHub Desktop.
Save kdhfred/7662b2596651e9099f87035a64953b21 to your computer and use it in GitHub Desktop.
Codility BinaryGap
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