22. Valid Palindrome

Easy · String

Given a string, determine if it is a valid palindrome, considering only alphanumeric characters and ignoring cases.

A palindrome is a word, phrase, or sequence that reads the same backward as forward. For this problem, spaces, punctuation, and other non-alphanumeric characters should be ignored, and the comparison should be case-insensitive.

Examples

Example 1
Input: "A man, a plan, a canal: Panama"
Output: true
Explanation: After removing non-alphanumeric characters and converting to lowercase: "amanaplanacanalpanama". This reads the same forwards and backwards.
Example 2
Input: "race a car"
Output: false
Explanation: After filtering: "raceacar". Reading backwards gives "racecar", which is different.

Constraints