Valid Palindrome

Two Pointers, problem 1 of 7

Valid Palindrome

Easy

LC #125

stringopposite ends

Not attempted yet

Given a string s, return True if it's a palindrome once you ignore everything that isn't a letter or digit and treat upper and lower case as equal. Otherwise return False.

Example 1

Input: s = "A man, a plan, a canal: Panama"
Output: True
Letters only: "amanaplanacanalpanama"

Example 2

Input: s = "race a car"
Output: False
"raceacar" reversed is "racaecar".

Example 3

Input: s = " "
Output: True
Nothing left after filtering: an empty
string is a palindrome.

Constraints

  • 1 ≤ len(s) ≤ 2 × 10⁵
  • s has printable ASCII characters only
  • Aim for O(1) extra space

Python

Loading draft…

Test results

10 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 7 hidden

Run examples, then submit all tests.