-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlargestNumber.py
More file actions
21 lines (19 loc) · 1.46 KB
/
largestNumber.py
File metadata and controls
21 lines (19 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# @param num, a list of integers
# @return a string
def largestNumber(num):
def strSort(x, y):
x = str(x)
y = str(y)
return 1 if (x + y) > (y + x) else -1
l = sorted(num, cmp=strSort, reverse=True)
print l
if l[0] == 0:
return '0';
ret = ''
for i in l:
ret += str(i)
return ret
assert largestNumber([0, 0]) == '0'
assert largestNumber([3, 30, 34, 5, 9]) == '9534330'
assert largestNumber([824,938,1399,5607,6973,5703,9609,4398,8247]) == '9609938824824769735703560743981399'
assert largestNumber([9051,5526,2264,5041,1630,5906,6787,8382,4662,4532,6804,4710,4542,2116,7219,8701,8308,957,8775,4822,396,8995,8597,2304,8902,830,8591,5828,9642,7100,3976,5565,5490,1613,5731,8052,8985,2623,6325,3723,5224,8274,4787,6310,3393,78,3288,7584,7440,5752,351,4555,7265,9959,3866,9854,2709,5817,7272,43,1014,7527,3946,4289,1272,5213,710,1603,2436,8823,5228,2581,771,3700,2109,5638,3402,3910,871,5441,6861,9556,1089,4088,2788,9632,6822,6145,5137,236,683,2869,9525,8161,8374,2439,6028,7813,6406,7519]) == '995998549642963295795569525905189958985890288238775871870185978591838283748308830827481618052787813771758475277519744072727265721971071006861683682268046787640663256310614560285906582858175752573156385565552654905441522852245213513750414822478747104662455545424532434289408839763963946391038663723370035134023393328828692788270926232581243924362362304226421162109163016131603127210891014'