[개발]programmers/Python3
Lv.2_다음 큰 숫자
dowon
2023. 1. 19. 19:34
def solution(n):
firstnum = format(n,'b').count('1')
nextnum = n + 1
while True:
countnum = format(nextnum,'b').count('1')
if countnum != firstnum:
nextnum += 1
else:
break
return nextnum
.count() : 특정 "문자열"에서 원하는 문자의 개수를 셀 수 있다
format( , 'b') : 숫자를 2진법으로 고쳐 "문자형"으로 반환해준다