在Python中,使用自定义排序,连接数组元素,使得结果将是这些元素中的最大值。
T = int(input("Enter number of test cases: "))
for _ in range(T):
N = int(input())
array = list(map(int, input().split()))
array = list(map(str, array))
array.sort(key=lambda x: (x * 3), reverse=True if '0' in array else False)
largest_num = ''.join(array)
print(largest_num)
# it is not solving for all test cases.
T = int(input("Enter number of test cases: "))
for _ in range(T):
N = int(input())
array = list(map(int, input().split()))
array = list(map(str, array))
def custom_sort(x):
return x * 3 if '0' not in x else 0
array.sort(key=custom_sort, reverse=True)
largest_num = ''.join(array)
print(largest_num)