easy
strings
two-pointers
Determine whether s is a palindrome after removing every non-alphanumeric character and comparing letters without regard to case.
Input / output
- Input:
s: string - Output: boolean
Examples
"A man, a plan, a canal: Panama"returnstrue."race a car"returnsfalse.
Constraints
0 <= s.length <= 200,000- Alphanumeric means the ASCII ranges
A-Z,a-z, and0-9.
Follow-up Can you solve it with two pointers and constant auxiliary space instead of building a cleaned copy?
Examples
Example 1
Input: s = "racecar"
Output: true
Example 2
Input: s = "a"
Output: true
Example 3
Input: s = "hello"
Output: false
🔒 5 hidden
Running will execute all 8 cases, including 5 hidden ones.