Skip to content

Commit 5ac4044

Browse files
authored
Create 0179-largest-number.py
Create the Python solution as the same solution in the YouTube video "https://www.youtube.com/watch?v=WDx6Y4i4xJ8"
1 parent 504f4eb commit 5ac4044

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: python/0179-largest-number.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def largestNumber(self, nums: List[int]) -> str:
3+
for i, n in enumerate(nums):
4+
nums[i] = str(n)
5+
6+
def compare(n1, n2):
7+
if n1 + n2 > n2 + n1:
8+
return -1
9+
else:
10+
return 1
11+
12+
nums = sorted(nums, key = cmp_to_key(compare))
13+
14+
return str(int("".join(nums)))

0 commit comments

Comments
 (0)