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.

用队列实现堆栈, 这个一般思维是用两个队列来回倒腾数据, 大神用一个队列而且并不总倒腾数据。

这就是大神和我等凡人的差距!!!

只在每次push的时候倒腾一下。


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容