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

김예원·2022년 9월 26일

coding_test

목록 보기
4/30

문제

코드

def solution(s):
    answer = [0, 0]
    while(s!='1'):
        if '0' in s:
            answer[1]+=len([c for c in s if c=='0'])
            s=[c for c in s if c!='0']
        cnt=len(s)
        s=bin(cnt)[2:]
        answer[0]+=1
    return answer
  • bin 함수를 사용해 문자열 개수 이진수로 변환

0개의 댓글