Valid Palindrome
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward.
Given a string s, return true if it is a palindrome. Otherwise, return false.
Example 1
Input
A man, a plan, a canal: Panama
Output
true
Explanation
After removing non-alphanumeric characters and converting to lowercase, the string becomes "amanaplanacanalpanama", which is a palindrome.
Example 2
Input
race a car
Output
false
Explanation
After preprocessing, the string becomes "raceacar", which is not the same when read backward.
Constraints
Hints:
Hint 1
Use two pointers, one starting from the beginning and the other from the end of the string.
Hint 2
Skip non-alphanumeric characters and compare the remaining characters after converting them to lowercase.
Author & Technical Reviewer
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output