class Solution:
# @param {string} s A string
# @return {boolean} Whether the string is a valid palindrome
def isPalindrome(self, s):
# Write your code here
if s == '' or len(s) == 1:
return True
str = ''
for i in range(len(s)):
if s[i].isalpha() or s[i].isdigit():
str += s[i].lower()
n = len(str)
for i in range(n):
if str[i] != str[n - i - 1]:
return False
return True
class Solution:
# @param {string} s A string
# @return {boolean} Whether the string is a valid palindrome
def isPalindrome(self, s):
# Write your code here
start, end = 0, len(s) - 1
while start < end:
while start < end and not s[start].isalpha() and not s[start].isdigit():
start += 1
while start < end and not s[end].isalpha() and not s[end].isdigit():
end -= 1
if start < end and s[start].lower() != s[end].lower():
return False
else:
start += 1
end -= 1
return True