admin管理员组文章数量:1516870
【Leetcode】
问题描述
Given a list of non negative integers, arrange them such that they form the largest number.
- 给定一个非负整数的列表,把它们排列成最大的数。
实例
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
- 例如: 列表[3, 30, 34, 5, 9],组成的最大数为 9534330.
注意事项
Note: The result may be very large, so you need to return a string instead of an integer.
- 注意:结果可能非常大,因此需要返回一个字符串而不是整形数。
代码
def largestNum(nums):nums = sorted([str(i) for i in nums], cmp=lambda x, y: cmp(y + x, x + y))return "".join(nums).lstrip() or '0'print largestNum([3, 30, 34, 5, 9])
本文标签: LeetCode
版权声明:本文标题:【Leetcode】 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/biancheng/1701355920a384397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论