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

Seohyun·2024년 9월 5일
0

알고리즘

목록 보기
31/36
def solution(s):
    answer = [0, 0] 
    while not s == '1':
        answer[0] += 1
        temp = s.count('1')
        answer[1] += len(s) - temp
        s = str(bin(temp))[2:]
        
    return answer

bin() 함수를 사용하면 앞에 '0b'가 붙음을 잊으면 안 되겠다...

profile
Hail hamster

0개의 댓글