Solution 2

mail@pastecode.io avatar
unknown
python
2 years ago
719 B
7
Indexable
Never
class Solution:
    def validPalindrome(self, s: str) -> bool:
        if(self.checkIfPalindrome(s) or len(s) < 3): return True
        start = 0
        end = len(s) -1
        for i in range(int(len(s)/2)):
            startString = s[:start] + s[start+1:]
            endString = s[:end] +s[end+1:]
            if(self.checkIfPalindrome(startString) or self.checkIfPalindrome(endString)):
                return True
            if(start == end):
                return False
            start += 1
            end -= 1
        return False
    def checkIfPalindrome(self, string):
        if(len(string) < 1):
            return False
        if(string == string[::-1]):
            return True
        return False