class Solution:
def isPalindrome(self, s: str) -> bool:
s=s.lower()
res=""
for i in range(len(s)):
if s[i]>='a' and s[i]<='z' or s[i]>='0' and s[i]<='9':
res=res+s[i]
#print(res)
return res[::-1]==res
LeetCode:125.验证回文串
最新推荐文章于 2024-07-22 17:09:43 发布
本文介绍了一个使用Python实现的判断字符串是否为回文的算法。该算法首先将字符串转换为小写并过滤掉非字母数字字符,然后通过比较字符串与其反转后的版本来判断其是否为回文。
297

被折叠的 条评论
为什么被折叠?



