본문 바로가기
코딩 테스트/문제 풀기

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

by hazel_ 2021. 3. 11.

 

def solution(n):
    binary_n = str(format(n, 'b'))
    count_n = binary_n.count('1')

    result=n+1

    while True:
        count_result = str(format(result, 'b')).count('1')
        if count_result == count_n:
            break
        result+=1

    return result

 

댓글