
双指针的简单题,需要注意的是只比较字母和数字,并且字母不区分大小写
python代码
def isPalindrome(self, s: str) -> bool:low, high = 0, len(s)-1while low <= high:while low<high and not s[low].isdigit() and not s[low].isalpha():low += 1while low<high and not s[high].isdigit() and not s[high].isalpha():high -= 1if s[low].lower() != s[high].lower():return Falselow += 1high -= 1return True
