What is a palindrome?
A Palindrome is a word, phrase, or sequence that reads the same backward as forward.
Why do developers need to know what a palindrome is, and why should they learn this?
- Palindromes are a commonly asked string manipulation / algorithm problem
- The example below is the easiest one.
- There are tons of palindrome questions ranging from easy to hard (see links at the end).
A Quick Palindrome Checking Method:
def reverse(s): return s[::-1] def isPalindrome(s): rev = reverse(s) if (s == rev): return True return False # s = "racecar" ans = isPalindrome(s) if ans == 1: print("Yes") else: print("No")
Quicker Palindrome Check:
str(n) == str(n)[::-1]