题解 | #最长回文子串#

最长回文子串

https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507

def len_max(a):
    i=0
    max_len=1
    while i<len(a):
        j=len(a)-1
        while i<=j:
            if  a[i]==a[j] and a[i:j+1]==''.join(list(reversed(a[i:j+1]))):
                max_len=max(max_len,j-i+1)
                break
            j-=1
        i+=1
    return max_len
while True:
    try:
        s=input()
        max_len=len_max(s)
        print(max_len)
    except:
        break

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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