[백준] 16943. 숫자 재배치

원숭2·2022년 1월 20일
0

백준

목록 보기
9/54
post-thumbnail

문제

풀이

  1. permutations 함수를 사용하여 모든 경우의 수를 만들어 냄.
  2. for문과 if문을 사용하여 완전 탐색.

코드

from itertools import permutations

def solution() :
    a, b = input().split()
    sub = list(map(lambda x : ''.join(x), permutations(a)))
    res = -1
    
    for s in sub :
        if int(b) >= int(s) and s[0] != '0' :
            res = max(res, int(s))
    
    print(res)   
      
solution()

0개의 댓글