Skip to content

Valid Palindrome

EasyTwo Pointers
Decode it first. Clues, constraints, pattern and plan before any code.

A phrase is a palindrome if it reads the same forwards and backwards once you lowercase every letter and throw away everything that is not a letter or digit. Given a string s, return true if it is a palindrome.

"A man, a plan, a canal: Panama"  →  true    ("amanaplanacanalpanama")
"race a car"                      →  false   ("raceacar")
" "                               →  true    (nothing left, which counts)

Try to solve it without building a cleaned-up copy of the string.

Constraints

  • 0 <= s.length <= 2 * 10^5
  • s contains only printable ASCII characters.
  • Use O(1) extra space.