📘
Valid Palindrome
EasyTwo Pointers
Given a string s, return True if it is a palindrome after converting all uppercase letters to lowercase and removing all non-alphanumeric characters, or False otherwise.
Example:
Input:
A man, a plan, a canal: Panama
Output:
True
Reasoning:
- The input string "A man, a plan, a canal: Panama" is converted to lowercase, resulting in "a man, a plan, a canal: panama".
- All non-alphanumeric characters (spaces, commas, colon) are removed from the string, yielding "amanaplanacanalpanama".
- The resulting string is then checked to see if it's a palindrome by comparing characters from the start and end, moving towards the center.
- Since "amanaplanacanalpanama" reads the same forwards and backwards, the function returns
True.
Constraints:
- 1 <= len(s) <= 2 * 10^5
- s consists only of printable ASCII characters
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.