list中的元素排列组合成最大的数

class Solution:
    # @param {integer[]} nums
    # @return {string}
    def largestNumber(self, nums):
        import itertools
        a = list(itertools.permutations(nums,len(nums)))
        d = []
        for i in a:
            str1 = ''
            for j in i:

                str1 += str(j)
            d.append(int(str1))
        return str(max(d))

solution = Solution()
print solution.largestNumber([1,2,3,4,5,6,7,8,9,0])

你可能感兴趣的:(python)