PYTHON3 - pass 1/3 test cases -- can someone have a look and provide some feedback --thanks!!


  • 0
    J
    class Solution:
        def longestPalindrome(self, s):
            start = 0
            longest_pal_count = 0
            longest_pal = ''
            i = 0
            const_i = 0
            while start < len(s):
                for j in range(len(s)):
                    i += const_i
                    i += j
                    if s[start:(i+1)] == s[i:None:-1] or s[start:(i+1)] == s[i-len(s):(start-1):-1]:
                        if len(s[start:(i+1)]) > longest_pal_count:
                            longest_pal = s[start:(i+1)]
                            longest_pal_count = len(s[start:(i+1)])
                            i = 0
                    else:
                        i = 0
                start += 1
                const_i += 1
            return(longest_pal)
    

    I'm passing 1/3 of the test cases I can't seem to crack the remaining; can anyone take a look at this code and provide some tips?
    THANKS!!!


Log in to reply
 

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