5. Longest Palindromic Substring

dynamic programming solution 
class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """
        
        d=[[False for j in xrange(len(s))]for i in xrange(len(s))]
        length,left,right=0,0,0 
        for i in xrange(len(s)):
            d[i][i]=True
            
        for i in xrange(len(s)):
            for j in xrange(i):
                d[j][i]=(s[j]==s[i] and (i-j<2 or d[j+1][i-1]))
                if(d[j][i] and length

你可能感兴趣的:(5. Longest Palindromic Substring)