Valid Palindrome After Normalization
Problem statement
Given a string s, determine whether its letters and digits form a palindrome when letter case is ignored.
Normalize the string conceptually using these rules:
- Keep only ASCII letters
AthroughZ,athroughz, and digits0through9. - Treat uppercase and lowercase versions of a letter as equal.
- Keep the retained characters in their original order. Do not rearrange them or delete any retained letter or digit.
Return true if the retained sequence reads identically in both directions, and false otherwise. An empty retained sequence is a palindrome.
Function
isValidPalindrome(s: String) → booleanExamples
Example 1
s = "A!b?b,a"return = trueFiltering punctuation and folding case gives abba, whose two outer pairs match.
Example 2
s = "0P"return = falseThe digit 0 must be retained. The normalized sequence 0p has different outer characters.
Constraints
0 <= s.length <= 20000.- Each character is printable ASCII, with a code from
32through126, inclusive.