class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
# 大佬写的
res = ''
for i in range(len(s)):
start = max(i - len(res) -1, 0)
temp = s[start: i+1]
if temp == temp[::-1]:
res = temp
else:
temp = temp[1:]
if temp == temp[::-1]:
res = temp
return res
# 我写的
# if len(s) == 1:
# return s
# if len(s) == 2:
# if s[0] != s[1]:
# return s[0]
# b = s[0]
# long = 1
# for i in range(len(s)):
# for j in range(len(s), i, -1):
# if j - 1 != i:
# if s[j - 1] == s[i]:
# a = s[i:j]
# if a == a[::-1]:
# if len(a) > long:
# b = a
# long = len(a)
# return b
if __name__ == '__main__':
solution = Solution
num = solution.longestPalindrome(solution, "babad")
print(num)
num = solution.longestPalindrome(solution, "cbbd")
print(num)
num = solution.longestPalindrome(solution, "aacabdkacaa")
print(num)
num = solution.longestPalindrome(solution, "abcda")
print(num)