Programmers 가장 큰 수

Solution

def solution(numbers):
    answer = sorted(numbers, key=lambda x:str(x)*3, reverse=True)
    result = ''.join(map(str, answer))
    return str(int(result))
  • 다른 사람 풀이
import functools

def comparator(a,b):
    t1 = a+b
    t2 = b+a
    #  t1이 크다면 1, t2가 크다면 -1, 같으면 0
    return (int(t1) > int(t2)) - (int(t1) < int(t2))

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