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 HubertDolny
def checkIfP(s):
print(s)
for i in range(len(s)):
if (s==s[::-1]):
return True
return False
def longest_palindromic(text):
table=[]
for k in range(len(text)):
for i in range(len(text)):
if not(text[k:i+1]==""):
if(checkIfP(text[k:i+1])):
table.append(text[k:i+1])
res= max(table, key=len)
print(res)
return res
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
Oct. 31, 2016