Coding Trainer

Valid Palindrome

EasyTwo Pointersk-two-pointersLC #125

Problem

Valid Palindrome

Given a string s, return true if it is a palindrome after converting all uppercase letters to lowercase and removing all non-alphanumeric characters.

Example 1:

Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.

Example 2:

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.

Example 3:

Input: s = " "
Output: true
Explanation: After removing non-alphanumeric characters, s is an empty string, which reads the same forward and backward.

Constraints:

  • 1 ≤ s.length ≤ 2 × 10⁵
  • s consists only of printable ASCII characters