728x90

나의 풀이
from functools import reduce
def solution(numbers):
return str(int(reduce(lambda acc, cur: str(acc) + str(cur), sorted(numbers, key=lambda x: str(x) * 3, reverse=True))))
cmp_to_key를 활용한 풀이 - 1
import functools
def comparator(a,b):
t1 = a+b
t2 = b+a
return (int(t1) > int(t2)) - (int(t1) < int(t2)) # t1이 크다면 1 // t2가 크다면 -1 // 같으면 0
def solution(numbers):
n = [str(x) for x in numbers]
n = sorted(n, key=functools.cmp_to_key(comparator),reverse=True)
answer = str(int(''.join(n)))
return answer반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] 모의고사 (0) | 2022.06.04 |
|---|---|
| [프로그래머스/파이썬] H-Index (0) | 2022.06.03 |
| [프로그래머스/파이썬] K번째수 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 이중우선순위큐 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 디스크 컨트롤러 (0) | 2022.06.03 |