用python实现回文检测器
from pythonds.basic import Deque
def palchecker(aString):
chardeque = Deque()
for ch in aString:
chardeque.addRear(ch)
stillEqual = True
#剩余字母为1或0则为true;
#剩余字母大于1,则同时移除两端字母,相同继续,不同返回false
while chardeque.size() > 1 and stillEqual:
first = chardeque.removeFront()
last = chardeque.removeRear()
if not first == last:
stillEqual = False
return stillEqual
print(palchecker('lsadasl'))
print(palchecker('abcd'))
print(palchecker('toot'))