Honestly, not much of a trick. Use two pointers (start and end) and compare if they are alphanumeric. Use ascii to accomplish this.
classSolution:defisPalindrome(self, s:str)->bool: i, j =0,len(s)-1while i < j:whilenot self.isAlphanumeric(s[i])and i < j: i +=1whilenot self.isAlphanumeric(s[j])and j > i: j -=1if s[i].lower()!= s[j].lower():returnFalse i, j = i +1, j -1returnTruedefisAlphanumeric(self, c:int):return(ord('A')<=ord(c)<=ord('Z')orord('a')<=ord(c)<=ord('z')orord('0')<=ord(c)<=ord('9'))