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.
1 class Solution(object): 2 def isPalindrome(self, s): 3 """ 4 :type s: str 5 :rtype: bool 6 """ 7 s = "".join([c.lower() for c in s if c.isalnum()]) 8 return s == s[::-1]
c.lower()将字符串c中的大写字母转换成小写
c.isalnum()判断是否是字母或数字,若是返回非零