class Solution:
"""
@param: s: A string
@return: Whether the string is a valid palindrome
"""
def isPalindrome(self, s):
# write your code here
from string import punctuation
if not s:
return True
s = s.translate(None, punctuation) # 去掉符号
s = s.replace(' ', '') # 去掉空格
s = s.lower() # 全部转换成小写
# print(s)
lens = len(s)
for i in range(lens/2):
if s[i] != s[lens - i - 1]:
return False
return True
lintcode:有效回文串
最新推荐文章于 2022-05-06 00:12:08 发布