12911 문제.
해답
def solution(n):
answer = 0
next_n = n
# 자연수 n의 이진수 1의 개수
n_one_count = format(n, 'b').count('1')
# 제한사항 n은 1,000,000 이하
while next_n < 1_000_000:
next_n += 1
# n의 다음 자연수의 이진수 1의 개수
next_n_one_count = format(next_n, 'b').count('1')
if n_one_count == next_n_one_count:
answer = next_n
break
return answer
출처:
https://school.programmers.co.kr/learn/courses/30/lessons/12911
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 42842. 카펫 (0) | 2024.05.05 |
---|---|
[프로그래머스] 12945. 피보나치 (0) | 2024.04.13 |
[프로그래머스] 12941. 최솟값 만들기 (0) | 2024.04.13 |
[프로그래머스] 12924. 숫자의 표현 (0) | 2024.04.13 |