Short O(n) python

  • 0
        def validPalindrome(self, s):
            def isPalindrome(s, i, j, deleted):
                while i < j:
                    if s[i] != s[j]: 
                        return not deleted and (isPalindrome(s, i+1, j, True) or isPalindrome(s, i, j-1, True))
                    i, j = i+1, j-1
                return True
            return isPalindrome(s, 0, len(s)-1, False)

Log in to reply

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