/125. Valid Palindrome

125. Valid Palindrome

Easy
Two Pointers52.9% acceptance

Given a string input_str, return True if, after converting all uppercase letters to lowercase and removing all non-alphanumeric characters, the resulting string reads the same forwards and backwards. Otherwise, return False. Alphanumeric characters are defined as English letters (a-z, A-Z) and digits (0-9).

Example 1

Input: "No lemon, no melon!"

Output: True

Explanation: After cleaning: "nolemonnomelon" is a palindrome.

Example 2

Input: "123abccba321"

Output: True

Explanation: After cleaning: "123abccba321" is a palindrome.

Example 3

Input: "Palindrome123"

Output: False

Explanation: After cleaning: "palindrome123" is not a palindrome.

Constraints

  • 1 <= len(input_str) <= 200000
  • input_str consists only of printable ASCII characters
Python (current runtime)

Case 1

Input: "Was it a car or a cat I saw?"

Expected: True

Case 2

Input: "hello world"

Expected: False

Case 3

Input: "!@#"

Expected: True

Case 4

Input: "Able was I, I saw elba"

Expected: True

Case 5

Input: "abc12321cba"

Expected: True