Beat 96% Python O(n) Solution

  • 0
    class Solution:
        def validPalindrome(self, s):
            :type s: str
            :rtype: bool
            if self.is_palindrome(s): return True
            left, right = 0, len(s)-1
            while left<right:
                if s[left] != s[right]:
                    return self.is_palindrome(s[:left]+s[left+1:]) or self.is_palindrome(s[:right]+s[right+1:])
                left, right = left+1, right-1
            return False
        def is_palindrome(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.