This should be exceeding time limit for a very long string 'aaaaa.......'


  • 0
    W

    Looks like python is too slow to pass the test

     class Solution(object):
     def shortestPalindrome(self, s):
    
     if self.isPld(s):
            return s
        
        for i in xrange(1, len(s), 1):
            if self.isPld(s[:-i]):
                center = s[:-i]
                right = s[-i:]
                left = right[::-1]
                return left + center + right
        return None
        
    def isPld(self, s):
        for i in xrange(len(s) / 2):
            if s[i] != s[len(s) - 1 - i]:
                return False
        return True

Log in to reply
 

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