handles 401/485 cases

This commit is contained in:
Jacob Delgado 2023-08-30 09:08:31 -07:00
parent 05ba99b479
commit 96d0e5df76

View File

@ -7,20 +7,28 @@ def isPalindrome(s):
:rtype: bool
"""
# Create a translation table to remove uppercase letters and special characters
translation_table = str.maketrans("","", string.punctuation + string.whitespace)
# translation_table = str.maketrans("","", string.punctuation + string.whitespace)
translation_table = ''.join(c.lower() if c.isupper() or c.isalnum() else '' for c in s if c.isalnum() or c in string.whitespace)
# print(translation_table)
if len(translation_table) == 2:
if translation_table[0] == translation_table[1]:
return True
else:
return False
# Use the translation table to remove uppercase letters and special characters
upper_string = s.translate(translation_table)
lower_string = upper_string.lower()
# upper_string = s.translate(translation_table)
# lower_string = upper_string.lower()
lower_string = translation_table
half = len(lower_string)/2
# Round the value down since middle value doesn't matter
halfdown = math.floor(half)
halfdown = int(math.floor(half))
# print(halfup)
# print(halfdown)
first = []
second = []
# print(lower_string)
print(lower_string)
for i in range(halfdown):
# print(i)
@ -37,4 +45,6 @@ def isPalindrome(s):
else:
return False
print(isPalindrome("A man, a plan, a canal: Panama"))
# print(isPalindrome("A man, a plan, a canal: Panama"))
# print(isPalindrome("aa"))
print(isPalindrome("0P"))