Valid Palindrome
A phrase is a palindrome when, after turning upper-case letters into lower case and dropping everything that isn't a letter or a digit, it reads the same forwards and backwards.
Given a string s, return true if it is a palindrome and false otherwise. A string with no letters or digits counts as a palindrome.
Constraints
- 1 ≤ length of
s≤ 100,000 shas printable ASCII characters only.
Example 1
Input
s = "Was it a car or a cat I saw?"
Output
true
Why:
Kept and lower-cased it is wasitacaroracatisaw, the same both ways.
Example 2
Input
s = "race a car"
Output
false
Why:
raceacar backwards is racaecar.
Example 3
Input
s = " "
Output
true
Why:
Nothing is left after dropping the space, and empty text is a palindrome.
Hints
Was this a good challenge?
- Solved by
- 0
- Submissions
- 0
- Accepted
- –