[프로그래머스] 다음 큰 숫자(Python)

vvo_ter·2022년 11월 4일
0

프로그래머스

목록 보기
22/28
post-thumbnail

💻 문제 - Lv.2


👉 제출 코드

def solution(n):
    binary_n = format(n, 'b')
    cnt1 = binary_n.count('1')
    while 1:
        n += 1
        inc_binary_n = format(n, 'b')
        cnt2 = inc_binary_n.count('1')
        if cnt1 == cnt2:
            break
    return n

format 함수를 이용한다. 이때 binary_n은 str이므로 count 함수를 사용한다.

profile
's Coding Memory

0개의 댓글