leetcode.5. 最长回文子串

 暴力法(通过95)

class Solution:
    @staticmethod
    def Str(iterator):
        re_strTemp = str()
        for i in iterator:
            re_strTemp += i
        return re_strTemp

    @staticmethod
    def extract(indexIn, indexOut, tupStr):
        return tupStr[indexOut: indexIn + 1]

    @staticmethod
    def Len(indexBack, indexFront):
        return indexBack - indexFront + 1
        
    def longestPalindrome(self, Str: str) -> str:
        tupStr = tuple(Str)
        tupStr_Len = len(tupStr)
        re_strTemp = str()
        re_strTemp_len = 0
        for indexOut in range(0, tupStr_Len):
            tempOut = tupStr[indexOut]
            for indexIn in range(indexOut, tupStr_Len):
                if tupStr[indexIn] == tempOut:
                    if (Solution.Len(indexIn, indexOut) >
                            re_strTemp_len):

                        strTemp = Solution.Str(
                            Solution.extract(
                                indexIn, indexOut, tupStr)
                        )

                        if strTemp == Solution.Str(
                                reversed(strTemp)
                        ):
                            re_strTemp = strTemp
                            re_strTemp_len = len(strTemp)
        return re_strTemp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值