Write a Python function that takes a string as input and returns the length of the longest palindromic substring within the string
Write a Python function that takes a string as input and returns the length of the longest palindromic substring within the string
Step by step
Solved in 3 steps with 1 images
Thank you but it does not the lemgth of the string. I want the out as len(aabbaa)
What could have wrong with my code below?
### START FUNCTION
def longest(s:str)->str: # The desired function,
n = len(s)
st = 0
maxi = 0
start = 0
dicti = {} # The desired function.
dicti[s[0]] = 0
for i in range(1, n):
if s[i] not in dicti:
dicti[s[i]] = i
else:
if dicti[s[i]] >= st: # Checking for the current and maxlength.
curi = i - st
if maxi < curi:
maxi = curi
start = st
st = dicti[s[i]] + 1
dicti[s[i]] = i
if maxi < i - st:
maxi = i - st
start = st
return s[start : start + maxi] # Maximum lenngth substing.
#print(longest("aabbaababa"))
### END FUNCTION