题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
import sys def find1(i,n,k): if i+k < len(n) and i-k >= 0 and n[i-k] == n[i+k]: return find1(i,n,k+1) else: return 2*k-1 def find2(i,j,n,k): if j+k < len(n) and i-k >= 0 and n[i-k] == n[j+k]: return find2(i,j,n,k+1) else: return 2*k n = input() m = len(n) k = 1 for i in range(1,m-1): if n[i] == n[i+1]: k = max(k,find2(i,i+1,n,0)) elif n[i-1] == n[i+1]: k = max(k,find1(i,n,2)) print(k)