680_Valid Palindrome II
Input:
"aba"
Output:
TrueInput:
"abca"
Output:
True
Explanation:
You could delete the character 'c'.Solution
Last updated
Input:
"aba"
Output:
TrueInput:
"abca"
Output:
True
Explanation:
You could delete the character 'c'.Last updated
class Solution(object):
def validPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
left, right = 0, len(s) - 1
while left < right:
if s[left] == s[right]:
left += 1
right -= 1
else:
temp1 = s[left : right] # if delete right element
temp2 = s[left+1 : right + 1] # if delete left element
return temp1 == temp1[::-1] or temp2 == temp2[::-1]
return True