Skip to content

Commit

Permalink
59.py
Browse files Browse the repository at this point in the history
  • Loading branch information
huisuu committed Aug 28, 2024
1 parent 156c41b commit cd377bf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions HSKIM/51to60/59.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from functools import cmp_to_key

def compare(a, b):
if a + b > b + a:
return -1
elif a + b < b + a:
return 1
else:
return 0

def solution(numbers):
# numbers를 문자열로 변환
numbers = list(map(str, numbers))

# 커스텀 비교 함수를 사용하여 정렬
numbers.sort(key=cmp_to_key(compare))

# 결과가 000...000 인 경우 0 반환
if numbers[0] == '0':
return '0'

# 정렬된 숫자들을 이어붙여 반환
return ''.join(numbers)

numbers = [6, 10, 2]
print(solution(numbers))

0 comments on commit cd377bf

Please sign in to comment.