题解 | #密码截取#

密码截取

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

n = input().strip() 
def palindrome(s, left, right): 
    while left >= 0 and right len(s) and s[left] == s[right]:
        left -= 1  
        right += 1  
    return s[left + 1:right]
res = "" 
for i in range(len(n)):
    s1 = palindrome(n, i, i)
    s2 = palindrome(n, i, i + 1)
    res = s1 if len(res) len(s1) else res
    res = s2 if len(res) len(s2) else res 
print(len(res))
全部评论

相关推荐

07-01 13:37
门头沟学院 Java
steelhead:不是你的问题,这是社会的问题。
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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