Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Longest Palindromic by mateusz.miekus
def longest_palindromic(text):
x=list(text)
pal=''
for i in range(len(text)):
for j in range(len(text)):
y=list(text)
if x[i]==x[j]:
pom=y[i:j+1]
if pom==pom[::-1]:
if len(pom)>len(pal):
pal=pom
return ''.join(pal)
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Dec. 2, 2016
Comments: