def longestPalindrome(self, s: str) -> str:
longest_palindrome, size = "", 0
# i is the index of the current center of the palindrome tested
for i in range(len(s)):
# Palindrome with odd number of caracters (center is s[i])
j = 1
while i-j >= 0 and i+j < len(s) and s[i-j]==s[i+j]:
j += 1
j -= 1 # go back one step as the last checked element were different
if 2 * j + 1 > size:
size = 2 * j + 1
longest_palindrome = s[i-j:i+j+1]
# Palindrome with even number of caracters (center between s[i] and s[i])
j = 1
while i-j+1 >= 0 and i+j < len(s) and s[i-j+1]==s[i+j]:
j += 1
j -= 1
if 2 * j > size:
size = 2 * j
longest_palindrome = s[i-j+1:i+j+1]
return(longest_palindrome)