diff --git a/palindrome_checker.py b/palindrome_checker.py index c0fdc30..a050a14 100644 --- a/palindrome_checker.py +++ b/palindrome_checker.py @@ -1,6 +1,15 @@ -# palindrome_checker.py def is_palindrome(s): - return s == s[::-1] + # Normalize the string: convert to lowercase and filter out non-alphanumeric characters + filtered_s = ''.join(c.lower() for c in s if c.isalnum()) + + # Use two-pointer technique to check for palindrome + left, right = 0, len(filtered_s) - 1 + while left < right: + if filtered_s[left] != filtered_s[right]: + return False + left += 1 + right -= 1 + return True if __name__ == "__main__": word = input("Enter a word: ")