输入包含多行,第一行包含一个整数n,代表字符串数组strs的长度,后面n行,每行一个字符串,代表strs[i](保证所有字符串长度都小于10)。
输出一行,包含一个字符串,代表返回的字典序最小的字符串。
2 abc de
abcde
2 b ba
bab
时间复杂度,额外空间复杂度。
import sys import functools n = int(input()) strs = list() while n >= 0: l = sys.stdin.readline().strip() if l is not '': strs.append(l) n = n - 1 def custom_sort(x, y): if (x+y) < (y+x): return -1 else: return 1 return 0 strs = sorted(strs,key = functools.cmp_to_key(custom_sort)) print(''.join(strs))