125 Valid Palindrome
class Solution:
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
def isalpha_or_digit(char):
return char.isalpha() or char.isdigit()
left = 0
right = len(s) - 1
while left < right:
# get the first valid left character
while left < right and not s[left].isalnum():
left += 1
# get the first valid right character:
while left < right and not s[right].isalnum():
right -= 1
if s[left].lower() != s[right].lower():
return False
left += 1
right -= 1
return TrueLast updated