Implementing a Palindrome Checker

78 views

Implementing a Palindrome Checker

Implementing a Palindrome Checker

How can I check if a string is a palindrome without using extra space?

solveurit24@gmail.com Changed status to publish February 19, 2025
0

A palindrome reads the same forwards and backwards. Here’s an efficient approach:


def is_palindrome(s):
    s = s.lower().replace(" ", "")
    return s == s[::-1]
print(is_palindrome("A man a plan a canal Panama"))  # Output: True

solveurit24@gmail.com Changed status to publish February 19, 2025
0