思路: 双指针
note: 只要左边或者右边删除一个字符后是回文即可。
class Solution:
def isPalindrome(self, s, low, high):
i, j = low, high
while i < j:
if s[i] == s[j]:
i += 1
j -= 1
else:
return False
return True
def validPalindrome(self, s: str) -> bool:
i, j = 0, len(s) -1
while i < j:
if s[i] == s[j]:
i += 1
j -= 1
else:
return self.isPalindrome(s, i, j-1) or self.isPalindrome(s, i+1, j)
return True