题解 | #密码截取#
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#最长回文子串 #DP text = input() length = len(text) left=0 right=0 dp=[[False]*length for _ in range(length) ] maxlen=0 for i in range(length): dp[i][i]=True for i in range(length-1,-1,-1): for j in range(i,length): if text[i] == text[j]: if j-i <=1: dp[i][j]=True else: dp[i][j] = dp[i+1][j-1] if dp[i][j] and j-i+1 >maxlen: maxlen = j-i+1 print(maxlen)