Palindrome Checker
easySave
StringTwo Pointers
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. A valid palindrome is a string that reads the same backward as forward.
Example 1
Input
[ "A man, a plan, a canal: Panama" ]
Output
true
Explanation. After removing all non-alphanumeric characters and converting to lower case, 'amanaplanacanalpanama' is a palindrome.
Example 2
Input
[ "race a car" ]
Output
false
Explanation. After cleaning, 'raceacar' is not read the same forward and backward.
Example 3
Input
[ " " ]
Output
true
Explanation. An empty string or a string with only whitespace characters is considered a palindrome.
Follow-up: Can you solve this problem by using a two-pointer technique to optimize the performance?
Constraints:
The input string will consist only of printable ASCII characters.
- Views
- 4