Python 9 line solution , but time limit is exceeding for submission


  • 0
    S

    Time limit is exceeding ,

    class Solution(object):
        def validPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            if s[::-1] == s:
                return True
            else:
                for i in range(len(s)):
                    temp = s
                    if temp[0:i]+temp[i+1:len(s)] == (temp[0:i]+temp[i+1:len(s)])[::-1]:
                        return True
                return False  
    

Log in to reply
 

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