891. Valid Palindrome II
Description:
Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome.
Example
Given s = “aba” return true
Given s = “abca” return true // delete c
Code:
class Solution:
"""
@param s: a string
@return: nothing
"""
def isPalindrome(self,s,cnt):
l = len(s)
start=0
end=l-1
while start<end:
if s[start] != s[end]:
if cnt>0:
cnt = 0
return self.isPalindrome(s[start+1:end+1],0) or self.isPalindrome(s[start:end],0)
else:
return False
elif s[start] == s[end]:
start+=1
end-=1
return True
def validPalindrome(self, s):
# Write your code here
return self.isPalindrome(s,1)