数组组成的最小数字
标题:数组组成的最小数字 | 时间限制:1秒 | 内存限制:262144K | 语言限制:不限
给定一个整型数组,请从该数组中选择3个元素组成最小数字并输出(如果数组长度小于3,则选择数组中所有元素来组成最小数字)。
from functools import cmp_to_key nums = sorted(map(int, input().split(',')))[:3] def cmp(x, y): return 1 if x + y >= y + x else -1 nums = sorted(list(map(str, nums)), key=cmp_to_key(cmp)) print(''.join(map(str, nums[:3])))