Created
October 4, 2014 16:39
-
-
Save dereknheiley/ea27900740cace91ef72 to your computer and use it in GitHub Desktop.
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
def solution(N): | |
#remove trailing zeros | |
while N%2==0: | |
N=N>>1 | |
#remove trailing 1 | |
N=N>>1 | |
maxGap=0 | |
while N>0: | |
gap=0 | |
#count zeros until the next 1 | |
while N%2==0: | |
gap+=1 | |
N=N>>1 | |
#remove trailing 1 | |
N=N>>1 | |
#save this gap | |
maxGap = gap>maxGap and gap or maxGap | |
return maxGap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment