Given a string str
, determine if it is a palindrome. Return true
if it is, and false
otherwise.
A string is a palindrome if, after changing all uppercase letters to lowercase and discarding all non-alphanumeric characters, it remains identical when read forward and backward. Alphanumeric characters consist of both letters and numbers.
str: string
: A stringInput: str = "No 'x' in Nixon"Output: trueExplanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes 'noxinnixon', which is a palindrome.
Input: str = "Was it a car or a cat I saw?"Output: trueExplanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes 'wasitacaroracatisaw', which is a palindrome.
Input: str = "tab a cat"Output: falseExplanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes 'tabacat', which is not a palindrome.
str.length
<= 1000str
consists only of printable ASCII charactersGiven a string str
, determine if it is a palindrome. Return true
if it is, and false
otherwise.
A string is a palindrome if, after changing all uppercase letters to lowercase and discarding all non-alphanumeric characters, it remains identical when read forward and backward. Alphanumeric characters consist of both letters and numbers.
str: string
: A stringInput: str = "No 'x' in Nixon"Output: trueExplanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes 'noxinnixon', which is a palindrome.
Input: str = "Was it a car or a cat I saw?"Output: trueExplanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes 'wasitacaroracatisaw', which is a palindrome.
Input: str = "tab a cat"Output: falseExplanation: After removing non-alphanumeric characters and converting to lowercase, the string becomes 'tabacat', which is not a palindrome.
str.length
<= 1000str
consists only of printable ASCII charactersconsole.log()
statements will appear here.