【发布时间】:2018-06-14 20:28:23
【问题描述】:
给定一个列表,例如: [3、30、34、5、9]。 输出:9534330 编写一个程序以返回可能的最大数
在我的代码中,我在这里使用了排列:
from itertools import permutations
x = [3, 30, 34, 5, 9]
y = permutations(x)
n = len(y)
e = []
for i in y:
a = map(str, i)
e.append(int("".join(i)))
print "Largest Number {}".format(sorted(e)[-1])
这里 n 表示排列数的长度是 120,因为 5!。 有没有更好的方法来解决这个问题?
【问题讨论】:
标签: python algorithm permutation