...

/

Solution Review: Check for a Palindrome

Solution Review: Check for a Palindrome

This review provides a detailed analysis of the solution to check whether or not a string is a palindrome.

We'll cover the following...

Solution: Using Recursion

Press + to interact
def isPalindrome(testVariable) :
# Base Case
if len(testVariable) <= 1 : # Strings that have length 1 or 0 are palindrome
return True
# Recursive Case
length = len(testVariable)
if testVariable[0] == testVariable[length - 1] : # compare the first and last elements
return isPalindrome(testVariable[1: length - 1])
return False
# Driver Code
print(isPalindrome("madam"))
...
Access this course and 1400+ top-rated courses and projects.