binary-gap

Seogyu Gim·2020년 11월 19일
def solution(N):
    # write your code in Python 3.6
    bN = str(format(N, '#b'))[2:]
    ret = []
    if bN.count('1') <= 1:
        return 0
    idx = -1
    while True:
        idx = bN.find('1', idx+1)
        next_i = bN.find('1', idx+1)
        if next_i == -1:
            break
        ret.append(next_i - idx -1)
    return max(ret)

Score: 100/100
Result-Link

profile
의미 있는 일을 하고싶은 개발자

0개의 댓글