Valid Palindrome

Easy · Two Pointers · Two Pointers · String

Problem

A phrase is a palindrome if, after lowercasing and discarding everything that is not a letter or digit, it reads the same forwards and backwards.

Given a string s, return whether it is a palindrome.

Examples

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

"amanaplanacanalpanama" reversed is itself.

Input: s = "race a car"
Output: False

"raceacar" is not a palindrome.

Input: s = " "
Output: True

Nothing survives the filter, and an empty string is a palindrome.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…