Palindrome check
Return True if s reads the same forwards and backwards, looking only at letters and digits and ignoring upper/lower case. "A man, a plan, a canal: Panama" is a palindrome.
Write is_palindrome(s) in Python, isPalindrome(s) in JavaScript or TypeScript, or int is_palindrome(char s[]) in C. Level: Easy.
Examples
Input: s = 'racecar' Output: True
Input: s = 'A man, a plan, a canal: Panama' Output: True
- 0 ≤ length of s ≤ 1000
- An empty string counts as a palindrome
Hint
First build a cleaned string: keep only letters and digits, in lower case. Then compare it with its reverse, or walk two pointers in from both ends.
The approach, step by step
- clean = letters and digits of s, lower case
- left = 0, right = last index
- left < right?
- clean[left] == clean[right]?
- left + 1, right − 1
- Return True
- Return False