https://school.programmers.co.kr/learn/courses/30/lessons/12911
def solution(n):
n_bin = str(format(n, 'b'))
one_cnt = n_bin.count('1')
next_num = n+1
while True:
next_bin = str(format(next_num, 'b'))
next_one_cnt = next_bin.count('1')
if one_cnt == next_one_cnt:
return next_num
else:
next_num += 1
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[1차] 비밀지도 (0) | 2022.11.14 |
---|---|
[Python] 시저 암호 (0) | 2022.11.13 |
[Python] 예산 (0) | 2022.11.11 |
[Python] 3진법 뒤집기 (0) | 2022.11.10 |
[Python] 이상한 문자 만들기 (0) | 2022.11.09 |