leetcode @python 125. Valid Palindrome
题目链接
https://leetcode.com/problems/valid-palindrome/
题目原文
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama"
is a palindrome.
"race a car" is not a palindrome.
题目大意
给定一个字符串,只考虑其中的数字和字母,忽略符号和大小写,判断是否一个回文串
解题思路
将字母都转成小写,过滤掉里面的符号,翻转字符串后和过滤后的字符串进行判断
代码
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
st = [c for c in s.lower() if c.isalnum()]
return st == st[::-1]