Leetcode

有更好的算法但愿指正,最长回串python

def get_long_str(s):
    l = list(s)
    result = dict()
    print(l.count(l[0]),len(l))
    if len(s) <= 1:
        return s
    elif l.count(l[0]) == len(l):
        return s
    else:
        for i in range(0, len(l)):
            for j in range(i + 1, len(l)):
                if l[i] == l[j]:
                    if j + 1 - i in result.keys():
                        pass
                    else:
                        tmp,tmp_b = l[i:j+1],l[i:j+1]
                        tmp_b.reverse()
                        if tmp==tmp_b:
                            result[j + 1 - i] = l[i:j + 1]
                            i =j
                else:
                    continue

    if len(result) == 0:
        return s[0]
    else:
        return ''.join(result[max(result.keys())])