leetcode-study

125. Valid Palindrome

class Solution:
    def isPalindrome(self, s: str) -> bool:
        """
        Check if the given string 's' is a palindrome.
        
        This function converts all uppercase letters to lowercase and ignores non-alphanumeric characters.
        It then uses the two-pointer technique to compare characters from both ends of the string.
        
        Parameters:
            s (str): The input string consisting of printable ASCII characters.
        
        Returns:
            bool: True if 's' is a palindrome after processing, otherwise False.
        """
        left = 0                     # Pointer starting from the beginning of the string.
        right = len(s) - 1           # Pointer starting from the end of the string.
        
        while left < right:
            # Skip non-alphanumeric characters from the left.
            while left < right and not s[left].isalnum():
                left += 1
            # Skip non-alphanumeric characters from the right.
            while left < right and not s[right].isalnum():
                right -= 1
            
            # Compare the characters at the pointers in lowercase form.
            if s[left].lower() != s[right].lower():
                return False         # If mismatch found, it's not a palindrome.
            
            left += 1                # Move the left pointer rightward.
            right -= 1               # Move the right pointer leftward.
        
        return True                  # If all characters match, the string is a palindrome.

Summary of Techniques and Approaches: