Skip to content
BASA DSA

Valid Palindrome

EasyTwo Pointers

Ignore nonalphanumeric ASCII characters and letter case. Return whether the remaining sequence reads the same in both directions.

Example 1

Input
s = "Was it a rat I saw?"
Output
true

Explanation

Removing punctuation and spaces and lowercasing gives wasitaratisaw, identical backwards.

Example 2

Input
s = "ab2a"
Output
false

Explanation

The digit 2 is retained; ab2a differs from its reverse a2ba.

Example 3

Input
s = "!?"
Output
true

Explanation

All characters are ignored, leaving an empty palindrome.

Constraints

  • 0 <= len(s) <= 200000
  • s is ASCII

Function contractisPalindromeArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…