暴力法(通过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