Created
January 10, 2020 08:41
-
-
Save ShinJJang/c6b192d4c272ae35428b6d48b239000d to your computer and use it in GitHub Desktop.
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): | |
max_length = 0 | |
length = 0 | |
quotient = N | |
remainder = 0 | |
is_occur_one = False | |
while quotient > 0: | |
quotient, remainder = divmod(quotient, 2) | |
if is_occur_one: | |
if remainder == 1: | |
max_length = length if length > max_length else max_length | |
length = 0 | |
else: | |
length += 1 | |
elif remainder == 1: | |
is_occur_one = True | |
return max_length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment