''' Author: LetMeFly Date: 2025-02-03 08:57:31 LastEditors: LetMeFly.xyz LastEditTime: 2025-02-03 08:59:26 ''' classSolution: defisOk(self, s: str, l: int, r: int) -> bool: while l < r: if s[l] != s[r]: returnFalse l += 1 r -= 1 returnTrue
defvalidPalindrome(self, s: str) -> bool: l, r = 0, len(s) - 1 while l < r: if s[l] != s[r]: returnself.isOk(s, l, r - 1) orself.isOk(s, l + 1, r) l += 1 r -= 1 returnTrue
funcisOk_VP(s string, l, r int)bool { for ; l < r; l, r = l + 1, r - 1 { if s[l] != s[r] { returnfalse } } returntrue }
funcvalidPalindrome(s string)bool { for l, r := 0, len(s) - 1; l < r; l, r = l + 1, r - 1 { if s[l] != s[r] { return isOk_VP(s, l, r - 1) || isOk_VP(s, l + 1, r) } } returntrue }