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 tigerhu3180
def longest_palindromic(text):
list1,set1=[],set()
for i in range(len(text)):
for j in range(i+1,len(text)+1):
s=text[i:j]
if s not in set1 and len(s)>1 and s==s[::-1]:list1.append(s)
set1.add(s)
return max(list1,key=len) if len(list1)>0 else text[0]
if __name__ == '__main__':
assert longest_palindromic("artrartrt") == "rtrartr", "The Longest"
assert longest_palindromic("abacada") == "aba", "The First"
assert longest_palindromic("aaaa") == "aaaa", "The A"
May 10, 2018