January 11, 2023
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization).
Let's take an example string
- “racecar” is a palindrome, because its last two characters are the same.
- simple check is if we reverse string the result is still same
- so we just loop string, then compare string from first index (
s[i]) and last index (
s[len(s)-1-i]) until reach the middle position
Here the sample implementation