题解 | #密码截取#
密码截取
http://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
字符串轮流充当对称的中心点,如果是偶数两个位置都是中心点 (1)分奇数和偶数两种情况 (2)判断是否超出边界 (3)假设一个最大值,如果后面更大的就覆盖掉
s = list(input())
def get_l(s, start, end):
while start>=0 and end<len(s) and s[start]==s[end]:
start -= 1
end += 1
return s[start+1:end]
r = 0
for i in range(len(s)):
temp1 = get_l(s, i, i)
temp2 = get_l(s, i, i+1)
L = max(len(temp1), len(temp2))
if r<L:
r=L
print(r)