lintcode:有效回文串

xiaoxiao2021-02-28  101

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
转载请注明原文地址: https://www.6miu.com/read-32382.html

最新回复(0)