- A phrase is a palindrome if it reads the same forward and backward after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters. Alphanumeric characters include letters and numbers.
- Given a string s, return True if it is a palindrome or False otherwise.
- This challenge corresponds to LeetCode #125.
1 <= s.length <= 2 * 105
- s consists only of printable ASCII characters.
s = "A man, a plan, a canal: Panama"
Explanation: “amanaplanacanalpanama” is a palindrome.
s = "race a car"
Explanation: “raceacar” is not a palindrome.
s = " "
Explanation: s is an empty string “” after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.
Below is my solution and some test cases. This solution has a linear time complexity O(n) and a constant space complexity O(1), where n is the length of the input string.