125. Valid Palindrome
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string
s, returntrueif it is a palindrome, orfalseotherwise.Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
def remove_non_alphanumeric(input_str):
result_str = ''.join(char for char in input_str if char.isalnum())
return result_str
def remove_non_alphanumeric(input_str):
result_str = ""
for char in input_str:
if char.isalnum():
result_str += char
return result_str