TLE Error in Python


#1
def largestNumber(self, a):
    a = list(a)
    for i in range(len(a)):
        for j in range(i+1,len(a)):
            one = str(a[i]) + str(a[j])
            two = str(a[j]) + str(a[i])
            if two > one:
                a[i], a[j] = a[j], a[i]
    ans = ''.join(map(str,a))
    if ans[0] == '0':
        return 0
    else:
        return ans

#2

try to solve it in linear time