Skip to content

Instantly share code, notes, and snippets.

@MrSimsek
Last active July 28, 2019 08:59
Show Gist options
  • Save MrSimsek/e090a2d3503feaf5fbd40e0195c777f0 to your computer and use it in GitHub Desktop.
Save MrSimsek/e090a2d3503feaf5fbd40e0195c777f0 to your computer and use it in GitHub Desktop.
# Palindrome 0(n) with efficient use of memory
def isPalindrome(string):
if string == "":
return None
for index in range(len(string)):
if string[index] != string[(len(string) - 1) - (index)]:
return False
return True
example = ""
if isPalindrome(example) == True:
print(f"Yes, {example} is a palindrome")
elif isPalindrome(example) == False:
print(f"No, {example} is not a palindrome")
else:
print(f"Not a word")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment