Wygeneruj program, który będzie w stanie znaleźć najdłuższy palindrom w podanym ciągu znaków.
String = "ababad"
def longestPallindrome(string):

#Check if string is empty
if (len(string) == 0):
return ""

#Define a data strocture and store the length of the longest pallindrome
pallindromes = [[0 for x in range(len(string))] for y in range(len(string))]
max_length = 0
start_pos = 0
#Calcolate the longest pallindrome
for i in range(len(string)):
pallindromes[i][i] = 1
for j in range(i):
if (string[j] == string[i] and (pallindromes[j+1][i-1] or i-j == 1)):
pallindromes[j][i] = 1
if (max_length < i - j + 1):
max_length = i-j + 1
start_pos = j

retorn string[start_pos:start_pos+max_length]