专栏名称: 每日一道算法题
学习算法是一种信仰,每天都需要坚持!
51好读  ›  专栏  ›  每日一道算法题

225. Implement Stack using Queues

每日一道算法题  · 公众号  · 算法  · 2017-05-30 22:30

正文

225. Implement Stack using Queues


Implement the following operations of a stack using queues.


push(x) — Push element x onto stack.

pop() — Removes the element on top of the stack.

top() — Get the top element.

empty() — Return whether the stack is empty.

Notes:

You must use only standard operations of a queue — which means only push to back, peek/pop from front, size, and is empty operations are valid.

Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue.







请到「今天看啥」查看全文