题解 | #最长回文子串#
最长回文子串
http://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
注意return hi-lo-1,其实是hi-lo-2+1
# -*- coding:utf-8 -*- class Solution: def getLongestPalindrome(self, A, n): # write code here def LongestPalindrome(s, lo, hi): while lo >= 0 and hi < len(s) and s[lo] == s[hi]: lo -= 1 hi += 1 return hi-lo-1 res = 0 for i in range(n-1): res = max(res, LongestPalindrome(A, i, i)) res = max(res, LongestPalindrome(A, i, i+1)) return res