最长回文子串

题目

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

Python

class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """
        long_str=''
        longest=0
        for i in range(len(s)):
            for j in range(len(s),i,-1):
                if(j-ilongest:
                        long_str=s[i:j]
                        longest=j-i
                    break
        return long_str

    def is_palindrome(self,s):
        reverse_str=''
        for i in range((len(s))//2):
            if s[i]!=s[-i-1]:
                return False
        return True

你可能感兴趣的:(最长回文子串)