Improving Python Code: Time limit exceded


  • 0
    A

    Can anyone help in imroving this code. I know i am doing a simple brute force.
    '''
    class Solution(object):
    def validPalindrome(self, s):
    if s :
    if self.checkpal(s):
    return True
    else :
    #logic for removing at most char
    for i in range(len(s)):
    temp = s[0:i] + s[i+1:]
    if self.checkpal(temp):
    return True
    return False
    #case for empty string
    else :
    return False

    def checkpal(self,s):
        if (s == s[::-1]):
            return True
        else:
            return False
    

    '''


Log in to reply
 

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