#使用双端队列判断是否为回文数
from pythonds.basic import Deque
def palchecker(aString):
chardeque=Deque()
for ch in aString:#使用for语句从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("toot"))
使用双端队列来判断是否为回文数(py)
最新推荐文章于 2024-08-08 15:12:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)