Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. The function should return a boolean indicating whether the input string is a palindrome.
String Manipulation and Two-Pointer Technique
i
) and one at the end (len(s) - 1 - i
) of the string.False
.True
.import re
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
s = s.lower()
s = re.sub(r'[^a-zA-Z\d]', '', s)
if len(s) == 0 or len(s) == 1:
return True
for i in range(len(s)):
if i == int(len(s) / 2):
return True
x = s[i]
y = s[len(s) - 1 - i]
if x != y:
return False
return True