#125 Valid Palindrome
A string counts as a palindrome here if, after dropping every character that isn't a letter or digit and lowercasing what remains, it reads the same forwards and backwards.
Given a string s containing printable ASCII, return true if it's a
palindrome under that definition, false otherwise.
Examples
s = "A man, a plan, a canal: Panama"trueStripped and lowercased it becomes "amanaplanacanalpanama", which reads the same in both directions.
s = "race a car"false"raceacar" is not the same reversed ("racaecar").
s = " "trueAfter filtering there's nothing left, and the empty string is a palindrome by convention.
Constraints
1 ≤ s.length ≤ 2 × 10⁵s consists of printable ASCII characters
The explainer is the good part.
Sign in for the full intuition build-up, every approach from naive to optimal with complexity analysis, progressive hints, and commented solutions in Python, JavaScript, and Java. All free.
Want a taste first? Try a free sample: Two Sum or Valid Parentheses.