题解 | 密码截取
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
def longest_palindrome(s):
if not s:
return 0
def expand_around_center(left, right):
while left >= 0 and right < len(s) and s[left] == s[right]:
left -= 1
right += 1
return right - left - 1
max_len = 0
for i in range(len(s)):
len1 = expand_around_center(i, i)
len2 = expand_around_center(i, i + 1)
max_len = max(max_len, len1, len2)
return max_len
inputs = input()
print(longest_palindrome(inputs))
