Skip to content

Commit 8bdd269

Browse files
authoredOct 23, 2019
Create 001.py
1 parent a59192a commit 8bdd269

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎ch01/001.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import functools
2+
3+
class Solution:
4+
def largestNumber(self, nums: List[int]) -> str:
5+
s = list(map(str, nums))
6+
7+
# 看 b + a,a + b 哪个比较大
8+
def comp(a, b): return 1 if a + b > b + \
9+
a else -1 if a + b < b + a else 0
10+
# 1. 降序
11+
# 2. 比较的逻辑需要定制,不再是比较大小了
12+
s.sort(reverse=True, key=functools.cmp_to_key(comp))
13+
return str(int(''.join(s)))

0 commit comments

Comments
 (0)
Please sign in to comment.