""" 0680.1 - Solution 1 - Two Pointer with One Skip """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def validPalindrome(self, s: str) -> bool:
"""Valid Palindrome II Function"""
def is_palindrome(left: int, right: int) -> bool:
"""Helper to check if substring s[left:right+1] is a palindrome."""
while left < right:
if s[left] != s[right]:
return False
left += 1
right -= 1
return True
left, right = 0, len(s) - 1
while left < right:
if s[left] != s[right]:
# Try skipping left char or right char
return is_palindrome(left + 1, right) or is_palindrome(left, right - 1)
left += 1
right -= 1
return True
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().validPalindrome("aba")) # True
print(Solution().validPalindrome("abca")) # True
print(Solution().validPalindrome("abc")) # False
print(Solution().validPalindrome("racecar")) # True
print(Solution().validPalindrome("deeee")) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()