Valid Palindrome - Problem
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward.
Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
Input & Output
Example 1 — Classic Palindrome
$
Input:
s = "A man, a plan, a canal: Panama"
›
Output:
true
💡 Note:
After cleaning: "amanaplanacanalpanama" reads the same forwards and backwards
Example 2 — Not a Palindrome
$
Input:
s = "race a car"
›
Output:
false
💡 Note:
After cleaning: "raceacar" vs reverse "racaecar" - they are different, so not a palindrome
Example 3 — Empty After Cleaning
$
Input:
s = " "
›
Output:
true
💡 Note:
After removing non-alphanumeric: empty string, which is considered a palindrome
Constraints
- 1 ≤ s.length ≤ 2 * 105
- s consists only of printable ASCII characters.
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code