Given a string S, find the longest palindromic substring in S. Substring of string S: S[ i....j] where 0 sisj< len(S). Palindrome string: A string which reads the same backwards. More formally, S is palindrome if reverse(S) =S. Incase of conflict, return the substring which occurs first ( with the least %3D starting index).
def longest_poly(s):
start = 0
l = len(s)
while start < l:
for i in range(len(s)-l):
tmp = s[start+i:start+i+l]
if tmp == tmp[::-1]:
return tmp
l -= 1
return -1
print(longest_poly("abcdcbd"))
Comments
Leave a comment