Valid Palindrome
Ignore nonalphanumeric ASCII characters and letter case. Return whether the remaining sequence reads the same in both directions.
Example 1
s = "Was it a rat I saw?"trueExplanation
Removing punctuation and spaces and lowercasing gives wasitaratisaw, identical backwards.
Example 2
s = "ab2a"falseExplanation
The digit 2 is retained; ab2a differs from its reverse a2ba.
Example 3
s = "!?"trueExplanation
All characters are ignored, leaving an empty palindrome.
Constraints
- 0 <= len(s) <= 200000
- s is ASCII
Function contract
isPalindromeArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
"Was it a rat I saw?"