题解 | #密码截取#

密码截取

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

字符串轮流充当对称的中心点,如果是偶数两个位置都是中心点 (1)分奇数和偶数两种情况 (2)判断是否超出边界 (3)假设一个最大值,如果后面更大的就覆盖掉

s = list(input())
def get_l(s, start, end):
    while start>=0 and end<len(s) and s[start]==s[end]:
        start -= 1
        end += 1
    return s[start+1:end]

r = 0
for i in range(len(s)):
    temp1 = get_l(s, i, i)
    temp2 = get_l(s, i, i+1)
    L = max(len(temp1), len(temp2))
    if r<L:
        r=L

print(r)

    
全部评论

相关推荐

05-20 13:59
门头沟学院 Java
米黑子米黑子:你这个成绩不争取下保研?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务