https://programmers.co.kr/learn/courses/30/lessons/42746
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from functools import cmp_to_key
# @cmp_to_key
def cmp(a,b):
t1 = int(a+b)
t2 = int(b+a)
if t1 > t2:
return 1
elif t1 < t2:
return -1
else:
return 0
def solution(numbers):
n = map(str, numbers)
n = sorted(n, key=cmp_to_key(cmp), reverse=True)
answer = str(int(''.join(n)))
return answer
Complexity
$O(nlogn)$
- $n$ = len(numbers)
PREVIOUSEtc