""" 0125.1 - Valid Palindrome - Solution 1 - Two Pointer Approach """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def isPalindrome(self, s: str) -> bool:
"""Valid Palindrome Function"""
l, r = 0, len(s) - 1
while l < r:
while l < r and not s[l].isalnum():
l += 1
while l < r and not s[r].isalnum():
r -= 1
if s[l].lower() != s[r].lower():
return False
l += 1
r -= 1
return True
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().isPalindrome("A man, a plan, a canal: Panama")) # True
print(Solution().isPalindrome("race a car")) # False
print(Solution().isPalindrome(" ")) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0125.2 - Valid Palindrome - Solution 2 - Filter and Reverse Compare """
#####################################################################################
# Imports
#####################################################################################
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def isPalindrome(self, s: str) -> bool:
"""Valid Palindrome Function"""
cleaned = ''.join(c.lower() for c in s if c.isalnum())
return cleaned == cleaned[::-1]
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().isPalindrome("A man, a plan, a canal: Panama")) # True
print(Solution().isPalindrome("race a car")) # False
print(Solution().isPalindrome(" ")) # True
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()