Why this code wrong? Any idea?


  • 0
    H
    class Solution:
        # @return a string
        def longestPalindrome(self, s):
            slen=len(s)
            llen=2*slen+1
            maxlen=0
            result=""
            if slen==1:
                return s
            for i in xrange(llen):
                j=i/2
                e=j+i%2
                while j>0 and e<slen and s[j-i]==s[e]:
                    j=j-1
                    e+=1
                    if e-j>=maxlen:
                        result=s[j:e]
                        maxlen=e-j
            return result

Log in to reply
 

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