难度:easy
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.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
思路:1. 回文结构只与字母数字有关,与其他符号和大小写无关,将string用 string.isalnum()得到string中所有的字母
和数字,将他们保存在list中,然后进行比较。
2.中间的程序是别人写出来的,只有两行,膜拜ing.
3. s.lower() 与s=s.lower() 是不一样的,前者不会将结果保存到原string中。
4. 处理之后的字符串不要保存到string里,会超时,而且比较起来出错,应该用list保存。具体原因不懂。