fromtypingimportListclassSolution:# ์ฝ์ ์ ๋ ฌ ๋ฌธ์
# ๊ฐ์ฅ ํฐ ์๋ฅผ ๋ง๋ค์ด์ ๋ฌธ์์ด๋ก ๋ฐํ
deflargestNumber(self,nums:List[int])->str:# ์์๋ฆฌ๊ฐ ๊ฐ์ฅ ํฐ ์๋ก ์ ๋ ฌ, ๊ทธ ๋ค์์๋ ๊ทธ ๋ค์ ์ซ์๋ค๋ก ์ ๋ ฌ
# ์ฝ์ ์ ๋ ฌ๋ ์ค์ ์ด์ฉํ๋ฉด ๋ ๋ฏ?
foriinrange(len(nums)):# Discusstion:
# The solution of the problem rests on observing that if AB > BA.
# Then we have ACB > BCA for any C.
forjinrange(i,0,-1):ifint(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]continuebreakreturnstr(int(''.join(list(map(str,nums)))))
Leave a comment