Constructing the largest number possible by rearranging a list

前端 未结 8 706
后悔当初
后悔当初 2020-12-16 11:53

Say I have an array of positive whole integers; I\'d like to manipulate the order so that the concatenation of the resultant array is the largest number possible. For exampl

8条回答
  •  庸人自扰
    2020-12-16 12:24

    import itertools
    def largestInt(a):
        b = list(itertools.permutations(a))
        c = []
        x = ""
        for i in xrange(len(b)):
            c.append(x.join(map(str, b[i])))
        return max(c)
    

提交回复
热议问题