Palindrome Checker
Write a function that checks if the given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, ignoring cases, spaces, and punctuation.
[ "A man, a plan, a canal: Panama" ]
Explanation. After ignoring punctuation, spaces, and case, 'AmanaplanacanalPanama' is a palindrome.
[ "race a car" ]
Explanation. After cleaning up the string, 'raceacar' is not a palindrome.
[ " " ]
Explanation. An empty string or a string with just spaces is considered a palindrome.
[ "Noon" ]
Explanation. Ignoring the case, 'noon' is a palindrome.
Follow-up: Can you optimize your solution to run in O(n) time complexity?
The input string will not be null and will have at least one character. Consider only alphanumeric characters while ignoring cases.
- Views
- 3