13. Valid Palindrome
Return whether s reads the same forward and backward after ignoring punctuation and spaces and comparing letters without case. Digits are compared exactly.
Punctuation and spaces do not participate in the comparison.
Example 1
Input
s = "Redder!"
Output
true
Explanation: Ignoring punctuation and letter case leaves redder, which reads the same in both directions.
Example 2
Input
s = "robot"
Output
false
Explanation: The remaining letters do not read the same backward.
Example 3
Input
s = " "
Output
true
Explanation: No letters or digits remain, so there is no mismatching pair.
Constraints
1 <= s.length <= 2 * 105- s contains printable ASCII characters only. Compare letters and digits case-insensitively, ignoring punctuation and spaces.
Hints
Hint 1
Write the exact eligible alphabet first.
Hint 2
Can you find the next retained symbol without storing it?
Hint 3
Skip ignored endpoints, compare folded symbols, then move inward.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Skip punctuation and compare without case
"A,b,a!"
true