版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_36372879/article/details/88066684
有空格,大写和小写,可以使用预处理的方法
class Solution:
def isPalindrome(self, s: str) -> bool:
if s == '':
return True
s = [c.lower() for c in s if c.isdigit() or c.isalpha()]
i, j = 0, len(s) - 1
while i < j:
if s[i] != s[j]:
return False
i, j = i + 1, j - 1
return True