ji-0630 / CodingTest

코딩테스트 연습 기록
0 stars 0 forks source link

다음 큰 숫자 #231

Closed ji-0630 closed 1 year ago

ji-0630 commented 1 year ago

문제 설명

image

ji-0630 commented 1 year ago

나의 풀이

def solution(n):
    one = bin(n).count("1")

    for i in range(n+1, 1000000):
        if bin(i).count("1") == one:
            return i
ji-0630 commented 1 year ago

다른 사람의 풀이

def nextBigNumber(n):
    num1 = bin(n).count('1')
    while True:
        n = n + 1
        if num1 == bin(n).count('1'):
            break
    return n