class Solution:
def isPalindrome(self, s: str) -> bool:
# 将字符串转换为小写,并移除所有非字母数字字符
filtered_s = ''.join(char.lower() for char in s if char.isalnum())
# 检查字符串是否正着读和反着读一样
return filtered_s == filtered_s[::-1]
python-leetcode-验证回文串
最新推荐文章于 2025-02-17 21:32:03 发布