MLE with python


  • 1
    class Solution(object):
    def longestPalindrome(self, s):
        """
        :type s: str
        :rtype: str
        """
        if self.isP(s):return s
        substr=['']
        l=0
        res=''
        for i in s:
            substr+=[i + sub for sub in substr]
        #substr=substr[::-1]
        for item in substr:
            if self.isP(item):
                if len(item)>l:
                    res=item
                    l=len(item)
        return res
            
    def isP(self,s):
        return s==s[::-1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.