leetcode:Largest Number
2016-02-13 10:59
309 查看
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given
Note: The result may be very large, so you need to return a string instead of an integer.
For example, given
[3, 30, 34, 5, 9], the largest formed number is
9534330.
Note: The result may be very large, so you need to return a string instead of an integer.
class Solution(object): def myCompare(self, s1, s2): n1 = int(s1+s2) n2 = int(s2+s1) if n1 < n2: return 1 elif n1 == n2: return 0 else: return -1 def largestNumber(self, nums): """ :type nums: List[int] :rtype: str """ strList = [str(x) for x in nums] strList.sort(cmp = self.myCompare) while len(strList) > 1 and strList[0] == '0': strList = strList[1:] return "".join(strList)
相关文章推荐
- HDU【3038】How Many Answers Are Wrong
- 最优布线问题
- 图(邻接矩阵)
- pig: ERROR 1070
- 2776 寻找代表元(匈牙利算法)
- Android Fragment完全解析,关于碎片你所需知道的一切
- C#里面Attribute的使用方法
- dx11学习笔记-1.创建一个空窗口
- 《笨办法学Python》 第38课手记
- PHP操作Mysql疑问?
- Nmap
- Codeforces Round #342 (Div. 2) 625C K-special Tables(脑洞)
- 【翻译自mos文章】怎么startup/shutdown PDB?
- UITableView如何撤销移动操作
- UITableView如何撤销移动操作
- python socket 解码IP层
- UITableView如何撤销移动操作
- css命名规范
- uvaoj-10082:WERTYU
- 房间声学原理与Schroeder混响算法实现