Note: we now only care about algorithm problems. So some problems are ignored.
Using built-in function will make it simple.
Solution:
# T:O(nlgn) S:O(1)
class Solution:
# @param num, a list of integers
# @return a string
def largestNumber(self, num):
num = [str(x) for x in num]
num.sort(cmp=lambda x, y: cmp(y + x, x + y))
largest = ''.join(num)
return largest.lstrip('0') or '0'
Run Time: 64 ms
No comments:
Post a Comment