-
[프로그래머스] 다음 큰 숫자 python(level 2)알고리즘 문제/풀어본 것 2022. 10. 30. 15:09
https://school.programmers.co.kr/learn/courses/30/lessons/12911?language=python3
1트
count함수를 통해 iterable한 객체에서 어떤 값이 몇개 들어있는지 확인할 수 있다.
bin(int형 숫자): int형 숫자가 2진수로 어떤 수인지 str형태로 리턴해준다. 0b~
oct(int형 숫자): int형 숫자가 8진수로 어떤 수인지 str형태로 리턴해준다. 0o~
hex(int형 숫자): int형 숫자가 16진수로 어떤 수인지 str형태로 리턴해준다. 0x~내 풀이
def solution(n): answer = n count_one = bin(n)[2:].count("1") while True: answer += 1 candidate = bin(answer) candi_count_one = candidate[2:].count("1") if candi_count_one == count_one: break return answer
'알고리즘 문제 > 풀어본 것' 카테고리의 다른 글
[프로그래머스] 숫자 게임 python (level 3) (0) 2022.10.30 [프로그래머스] 짝지어 제거하기 python (level 2) (1) 2022.10.30 [프로그래머스] 피보나치 수 python(level 2) (0) 2022.10.30 [프로그래머스] 숫자의 표현 python(level 2) (0) 2022.10.30 [프로그래머스] 이진 변환 반복하기 python(level 2) (0) 2022.10.30