题解 | #密码截取#

密码截取

https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1

s = input()
# 奇数类型:ABA
# 偶数类型:ABBA
max_len = 1
# 奇数
for i in range(len(s)):
    left, right = i, i
    while left >= 0 and right < len(s) and s[left] == s[right]:
        if max_len < right - left + 1:
            max_len = right - left + 1
        left -= 1
        right += 1
# 偶数
for i in range(len(s)):
    left, right = i, i + 1
    while left >= 0 and right < len(s) and s[left] == s[right]:
        if max_len < right - left + 1:
            max_len = right - left + 1
        left -= 1
        right += 1
print(max_len)

全部评论

相关推荐

牛客52811839...:实习要写出来业务和产出,你这写的像流水账没人看。项目经历也没有,换个极简简历试试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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