题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
# manacher
inStr=input()
extStr = " " + ' '.join(inStr) + ' '
maxLen = 0
center = 0
maxRight = 0
lenList = [0] * len(extStr)
# manacher
for i in range(len(extStr)):
if maxRight > i:
lenList.append(min(maxRight-i, lenList[2*center - i]))
while i >= lenList[i] and i + lenList[i] < len(extStr) and extStr[i-lenList[i]] == extStr[i+lenList[i]]:
lenList[i] += 1
if lenList[i] + i >= maxRight:
center = i
maxRight = i + lenList[i]
maxLen = max(lenList) - 1
print(maxLen)
