개발자식

[Codility Lesson1] Iteration 본문

Algorithm/Codility

[Codility Lesson1] Iteration

밍츠 2022. 6. 23. 22:23

1. iteration

문제 : app.codility.com/programmers/lessons/1-iterations/

def solution(N):
    
    binary = format(N, 'b')

    m = 0
    count = 0
    for i in binary:
        if '1' == i:
            if m < count :
                m = count
            count = 0
        else :
            count += 1

    return m

- binary 값이 정수가 아닌 문자열

- 순환할때 최대한 조건을 간략하게 구현

- 숫자가 1이지만 count가 0 이면 max 값이 바뀌지 않고 초기화까지도 가능

Comments