Today
Total
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
관리 메뉴

기억은 짧고 기록은 길다

[프로그래머스/Programmers] 이진 변환 반복하기 - Python 본문

CodingTest/programmers

[프로그래머스/Programmers] 이진 변환 반복하기 - Python

ukunV 2021. 9. 21. 00:02

Link

 

코딩테스트 연습 - 이진 변환 반복하기

 

programmers.co.kr

 

Solution

def solution(s):
    answer = [0, 0]

    while s != '1':
        count_0 = s.count('0')
        count_1 = s.count('1')

        answer[0] += 1
        answer[1] += count_0

        s = bin(count_1)[2:]

    return answer
🔑 key point: count(), bin()
📌 Tip: bin()[2:]
Comments