给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
说明:本题中,我们将空字符串定义为有效的回文串。
class Solution:
def isPalindrome(self, s: str) -> bool:
s = s.lower()
start,end = 0,len(s)-1
while start < end:
if not s[start].isalnum():
start+=1
continue
if not s[end].isalnum():
end -=1
continue
if s[start] != s[end]:
return False
else:
start+=1
end-=1
return True