Skip to content

Instantly share code, notes, and snippets.

@hillscottc
Created May 31, 2014 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hillscottc/ee04f082b0023037263b to your computer and use it in GitHub Desktop.
Save hillscottc/ee04f082b0023037263b to your computer and use it in GitHub Desktop.
A Palindrome Checker Using Deque (palchecker)
from pythonds.basic.deque import Deque
def palchecker(aString):
chardeque = Deque()
for ch in aString:
chardeque.addRear(ch)
stillEqual = True
while chardeque.size() > 1 and stillEqual:
first = chardeque.removeFront()
last = chardeque.removeRear()
if first != last:
stillEqual = False
return stillEqual
print(palchecker("lsdkjfskf"))
print(palchecker("radar"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment