Palindrome Check
Given a string, write a function to check if it is a palindrome. Consider only alphanumeric characters and ignore cases.
[ "A man, a plan, a canal: Panama" ]
Explanation. After removing non-alphanumeric characters and converting all to lower case, 'amanaplanacanalpanama' is a palindrome.
[ "race a car" ]
Explanation. After processing, 'raceacar' is not a palindrome.
[ "" ]
Explanation. An empty string is considered a palindrome.
[ " " ]
Explanation. A single space, when cleaned of non-alphanumeric characters, leaves an empty string which is a palindrome.
Follow-up: Can you solve the problem in O(n) time and O(1) space complexity? What changes would you make to handle Unicode characters?
The input string may contain non-alphanumeric characters and may be empty.
- Views
- 4