class Solution:
def largestNumber(self, nums: List[int]) -> str:
arr = [str(num) for num in nums]
res = []
while arr:
maxi = 0
for i in range(1, len(arr)):
if arr[i] + arr[maxi] > arr[maxi] + arr[i]:
maxi = i
res.append(arr[maxi])
arr.pop(maxi)
result = "".join(res)
return result if result[0] != '0' else '0'Where is the size of the array and is the total number of digits in the array .
class Solution:
def largestNumber(self, nums: List[int]) -> str:
for i, num in enumerate(nums):
nums[i] = str(num)
def compare(n1, n2):
if n1 + n2 > n2 + n1:
return -1
else:
return 1
nums = sorted(nums, key=cmp_to_key(compare))
return str(int("".join(nums)))Where is the total number of digits in the array .