题解 | #最长回文子串#

最长回文子串

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

def cut(s:str):
    results = []
    # x + 1 表示子字符串长度
    for x in range(len(s)):
        # i 表示偏移量
        for i in range(len(s) - x):
            results.append(s[i:i + x + 1])
    return results
def ishui(string):
    """
    判断是否为回文串
    """
    left = 0
    rigth = len(string)-1
    while (left < rigth):
        if (string[left] != string[rigth]):
            return False
        left += 1
        rigth -= 1
    return True
    
while True:
    try:
        n_str = input()
        #n_str = "abcbaaa"
        res = cut(n_str)
        #print(res)
        n_len = []
        #?print(res)
        for ele in res:
            if ishui(ele) ==True:
                n_len.append(len(ele))
        print(max(n_len))
        break
    except:
        break

实在人的暴力求解方法,大神的做法做不来

全部评论

相关推荐

07-15 12:24
重庆大学 运营
坏消息:和好工作擦肩而过
给点吧求求了:怎么可能因为差几秒,估计就是简历更好看婉拒了
点赞 评论 收藏
分享
Rena1ssanc...:对的,要是面评没太烂,勤更新简历等捞就行了,腾讯可以无限复活
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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