680. Valid Palindrome II
string,logic
Input: s = "aba"
Output: trueInput: s = "abca"
Output: true
Explanation: You could delete the character 'c'.Input: s = "abc"
Output: falseLast updated
string,logic
Input: s = "aba"
Output: trueInput: s = "abca"
Output: true
Explanation: You could delete the character 'c'.Input: s = "abc"
Output: falseLast updated
Index: 0 1 2 3 4 5 6 7 8
Char: c u p u u p u c uclass Solution:
def validPalindrome(self, s: str) -> bool:
l,r = 0,len(s)-1
def is_palindrome(s: str) -> bool:
return s == s[::-1]
while l <= r:
if s[l] != s[r]:
return is_palindrome(s[l+1:r+1]) or is_palindrome(s[l:r])
l += 1
r -= 1
return True