Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
Note: For the purpose of this problem, we define empty string as valid palindrome.
Input: "A man, a plan, a canal: Panama" Output: true
Input: "race a car" Output: false
class Solution:
def isPalindrome(self, s: str) -> bool:
s = ''.join([c for c in s if c.isalnum()]).lower()
i, j = 0, len(s) - 1
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
class Solution:
def isPalindrome(self, s: str) -> bool:
s = ''.join([c for c in s if c.isalnum()]).lower()
return s[::-1] == s