Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Created January 10, 2020 08:41
Show Gist options
  • Save ShinJJang/c6b192d4c272ae35428b6d48b239000d to your computer and use it in GitHub Desktop.
Save ShinJJang/c6b192d4c272ae35428b6d48b239000d to your computer and use it in GitHub Desktop.
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