题目大意
验证回文字符串 Ⅱ
给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。解题思路
双指针的方法解决
class Solution:def validPalindrome(self, s: str) -> bool:def checkPalindrome(low, high):i, j = low, highwhile i < j:if s[i] != s[j]:return Falsei += 1j -= 1return Truelow, high = 0, len(s) - 1while low < high:if s[low] == s[high]:low += 1high -= 1else:return checkPalindrome(low + 1, high) or checkPalindrome(low, high - 1)return True
