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

yewon Lee·2023년 9월 4일
0

😎코딩테스트 연습>월간 코드 챌린지 시즌1>이진 변환 반복하기


📘 문제풀이

def solution(s):
    cnt_0 = 0
    cnt_num = 0
    
    while s != '1':
        cnt_0 += s.count("0")
        s = s.replace("0", "")
        s = str(format(len(s), 'b'))
        cnt_num += 1
        
    return [cnt_num, cnt_0]
십진수 -> 이진수
format(int_num, 'b')

앞에 문자를 떼고 숫자만 반환
profile
시작

0개의 댓글