题解 | #最长回文子串#

最长回文子串

https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af

#

# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param A string字符串 
# @return int整型
#
class Solution:
    def is_huiwen(self,a:str):
        count = len(a)
        for i in range(int(count/2)):
            if a[i] != a[count-i-1]:
                return False
        return True

    def getLongestPalindrome(self , A: str) -> int:
        count = len(A)
        if count <= 1:
            return count
        max_value = 1
        #tmp = [1 for _ in range(count)]

        for i in range(1,count):
            for j in range(0,i-max_value+1):
                if self.is_huiwen(A[j:i+1]):
                    if len(A[j:i+1]) > max_value:
                        max_value =  len(A[j:i+1])
                        continue
        return max_value

全部评论

相关推荐

每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
07-10 11:08
门头沟学院 Java
投递京东等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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