#34EasyTwo Pointers

Valid Palindrome

Return true if a string is a palindrome after converting letters to lowercase and removing non-alphanumeric characters.

Constraints

  • •1 ≤ s.length ≤ 2 × 10⁵
Solution inPython
Python
def isPalindrome(s: str) -> bool:
    clean = ''.join(c.lower() for c in s if c.isalnum())
    return clean == clean[::-1]
How it works

Filter to alphanumeric characters with filter(str.isalnum, s), convert to lowercase, then compare with its reverse. O(n) time and space. Alternative two-pointer approach uses O(1) space.