[백준] 2992번 크면서 작은 수

거북이·2023년 3월 14일
0

백준[실버3]

목록 보기
61/92
post-thumbnail

💡문제접근

  • 정수 X와 구성이 같으면서 X보다 큰 최초의 수를 출력해야하므로 permutations를 오름차순 정렬 수행한 다음 찾아줘야한다.

💡코드(메모리 : 31256KB, 시간 : 40ms)

from itertools import permutations
import sys
input = sys.stdin.readline

flag = False
X = list(input().strip())
temp = int(''.join(map(str, X)))
for i in sorted(permutations(X, len(X))):
    t = int(''.join(map(str, i)))
    if temp < t:
        flag = True
        break

if flag:
    print(t)
else:
    print(0)

💡소요시간 : 14m

0개의 댓글