class Solution: def longestPalindrome(self, s): """ :type s: str :rtype: str """ n = len(s) s2='$#'+'#'.join(s)+'#@' ct =[0]*(2*n+4) mid=1 for cur in range(1,2*n+2): if cur mid+ct[mid]:mid = cur mx = max(ct) idxs = [i for i,j in enumerate(ct) if j == mx] p = idxs[0] for i in idxs: if s2[i]=='#':p = i rst =s2[p-mx+1:p+mx].replace('#','') return rst