Solution
from typing import List
class Solution:
# ์ฝ์
์ ๋ ฌ ๋ฌธ์
# ๊ฐ์ฅ ํฐ ์๋ฅผ ๋ง๋ค์ด์ ๋ฌธ์์ด๋ก ๋ฐํ
def largestNumber(self, nums: List[int]) -> str:
# ์์๋ฆฌ๊ฐ ๊ฐ์ฅ ํฐ ์๋ก ์ ๋ ฌ, ๊ทธ ๋ค์์๋ ๊ทธ ๋ค์ ์ซ์๋ค๋ก ์ ๋ ฌ
# ์ฝ์
์ ๋ ฌ๋ ์ค์ ์ด์ฉํ๋ฉด ๋ ๋ฏ?
for i in range(len(nums)):
# Discusstion:
# The solution of the problem rests on observing that if AB > BA.
# Then we have ACB > BCA for any C.
for j in range(i, 0, -1):
if int(str(nums[j - 1]) + str(nums[j])) < int(str(nums[j]) + str(nums[j - 1])):
nums[j - 1], nums[j] = nums[j], nums[j - 1]
continue
break
return str(int(''.join(list(map(str, nums)))))
Reference
Leave a comment