classSolution: defisValidChar(self, s): if'a' <= s <= 'z': returnTrue if'A' <= s <= 'Z': returnTrue if'0' <= s <= '9': returnTrue returnFalse
defisPalindrome(self, s: str) -> bool: n = len(s) if n <= 1: returnTrue left = 0 right = n-1 mid = left + (right-left)//2 while left < right: while left < n andnot self.isValidChar(s[left]): left += 1 while right > -1andnot self.isValidChar(s[right]): right = right - 1 # print(left, right) if left < right: if s[left].lower() != s[right].lower(): returnFalse else: left += 1 right = right - 1 returnTrue