题解 | #密码截取#

密码截取

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)


全部评论

相关推荐

05-09 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务