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, return true if it is a palindrome, or false otherwise.
Leetcode Solution (Python)
class Solution:
def isPalindrome(self, s: str) -> bool:
# To lower case
s = s.lower()
# Remove puncutation
s = s.translate(str.maketrans('', '', string.punctuation))
# Remove space
s = s.replace(" ", "")
# Two pointers
l = 0
r = len(s)-1
while l<r:
if s[l]!=s[r]:
return False
l+=1
r-=1
return True
Elements of Programming Interviews in Python: The Insiders’ Guide