[LeetCode]125. Valid Palindrome
125. Valid Palindrome
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
if not s:
return True
strs = ''.join(filter(lambda x:x.isalnum(), s.lower()))
left, right = 0, len(strs)-1
while left <= right:
if strs[left] != strs[right]:
return False
left += 1
right -= 1
return True
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
string = filter(str.isalnum, str(s)).lower()
return string == string[::-1]
关注公众号:数据结构与算法那些事儿,每天一篇数据结构与算法