Python solution


  • 0
    B
    def Solution(_input):
        remaining = map(str, _input)
        result = ""
        def LargestNumber(arr, index):
            num_dict = {}
            if len(arr) == 1:
                return [arr[0]]
            for s in arr:
                char = s[len(s)-1] if len(s)-1 < index else s[index]
                if char in num_dict:
                    num_dict[char].append(s)
                else:
                    num_dict[char]=[s]
            if len(num_dict.keys())==1:
                return num_dict.values()[0]
            return LargestNumber(num_dict[max(num_dict.keys())], index+1)
        while remaining:
            l = LargestNumber(remaining, 0)
            for s in l:
                remaining.remove(s)
                result += s
        return result 
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.