class Solution:
def isPalindrome(self, s: str) -> bool:
n = len(s)
if n ==0:
return True
i = 0
j= n-1
while i<j:
while i<j and not s[i].isalnum():
i += 1
while i<j and not s[j].isalnum():
j -= 1
# print(s[i],s[j])
if i<j:
if s[i].lower()!=s[j].lower():
return False
i += 1
j -= 1
return True
每日一道Leetcode - 125. 验证回文串【双指针|回文串】
最新推荐文章于 2024-05-30 18:05:01 发布