最长回文子串(Python)
最长回文子串
http://www.nowcoder.com/questionTerminal/b4525d1d84934cf280439aeecc36f4af
# -*- coding:utf-8 -*- class Palindrome: def getstr(self,A,n): re = [] for i in range(n): for j in range(i + 1,n + 1): re.append(A[i:j]) return re def choose(self,A,n): tmp = [] for k in self.getstr(A,n): if k == k[::-1]: tmp.append(len(k)) return tmp def getLongestPalindrome(self, A, n): # write code here res = self.choose(A, n) return max(res)