Palindrome Check Ignoring Symbols
Problem statement
You are given a string s. Decide whether it reads the same forwards and backwards when you look only at its letters and digits.
Skip every other character, such as spaces and punctuation, and treat uppercase and lowercase forms of a letter as the same. If no letter or digit is left, the answer is true.
Return true if s is a palindrome by this rule, and false otherwise.
Function
isPalindrome(s: String) → booleanExamples
Example 1
s = "Step on no pets!"return = trueKeeping letters only and ignoring case gives steponnopets, which reads the same backwards.
Example 2
s = "Ab2,b-A1"return = falseThe kept characters are ab2ba1. Digits count, so the final 1 breaks the match with the first a.
Example 3
s = "?! ."return = trueNo letter or digit is left, and an empty sequence is a palindrome.
Constraints
1 <= s.length <= 2 * 10^4scontains only printable ASCII characters (codes 32 to 126), including spaces.