题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
string = input().strip()
max_len = 0
for i in range(0, len(string)):
left = i - 1
right = i + 1
len_ABA = 1
while left >=0 and right <= len(string) - 1:
if string[left] == string[right]:
len_ABA += 2
left -= 1
right += 1
else:
break
left = i
right = i + 1
len_ABBA = 0
while left >= 0 and right <= len(string) - 1:
if string[left] == string[right]:
len_ABBA += 2
left -= 1
right += 1
else:
break
max_len = max([max_len, len_ABA, len_ABBA])
print(max_len)