class Solution:
"""
@param s: A string
@return: Whether the string is a valid palindrome
"""
def isPalindrome(self, s):
# write your code here
left, right = 0, len(s) - 1
while left < right:
while left < right and not s[left].isalnum():
left += 1
while left < right and not s[right].isalnum():
right -= 1
if s[left].lower() != s[right].lower():
return False
left += 1
right -= 1
return True
class Solution:
"""
@param s: A string
@return: Whether the string is a valid palindrome
"""
def isPalindrome(self, s):
# write your code here
if s == None:
return False
if len(s) == 0:
return True
s_new = ""
for i in range(len(s)):
if s[i].isalnum():
s_new += s[i].upper()
N = len(s_new)
for i in range(N//2):
if s_new[i] != s_new[N-i-1]:
return False
return True