Dashboard Temp Share Shortlinks Frames API

HTMLify

Form the Largest Number
Views: 9 | Author: prakhardoneria
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from functools import cmp_to_key

class Solution:
    def findLargest(self, arr):
        arr = list(map(str, arr))
        
        def compare(a, b):
            if a + b > b + a:
                return -1
            else:
                return 1
        
        arr.sort(key=cmp_to_key(compare))
        
        result = "".join(arr)
        
        return "0" if result[0] == "0" else result