LeetCode学习之-225. 利用队列实现堆栈(Implement Stack using Queues)
来源:互联网 发布:淘宝洋垃圾服装 编辑:程序博客网 时间:2024/06/06 01:25
1.算法
[1]
2.代码
[2]
"""Author: Tianze TangDate: 2017-07-17Email:454779758@qq.comFunction: Use two queue to realize stack's function.Explain:Modified Log:"""class MyStack(object): def __init__(self): """ Initialize your data structure here. """ self.Queue= [] def push(self,x): self.Queue.append(x) def pop(self): return(self.Queue.pop()) def empty(self): return not self.Queue def top(self): return(self.Queue[-1])a = MyStack()a.push(1)print(a.Queue)a.push(2)print(a.Queue)print(a.top())print(a.top())
3.输出
[1]
[1, 2]
2
2
4.参考资料
[1] 《算法导论》第3版 :第10章 基本数据结构 10.1栈和列队
[2] 225. Implement Stack using Queues
阅读全文
0 0
- LeetCode学习之-225. 利用队列实现堆栈(Implement Stack using Queues)
- leetcode 225. Implement Stack using Queues 双队列实现栈
- LeetCode 225 Implement Stack using Queues(利用队列实现栈)
- LeetCode OJ 之 Implement Stack using Queues(使用队列实现栈)
- 225. Implement Stack using Queues (用队列实现栈)
- LeetCode学习之-232. 利用堆栈实现队列(Implement Queue using Stacks)
- LeetCode 225. Implement Stack using Queues(使用队列来实现栈)
- Leetcode 225 Implement Stack using Queues 使用队列实现栈
- 两个队列实现一个栈[leetcode]Implement Stack using Queues
- LeetCode Implement Stack using Queues 栈&队列
- 225.Implement Stack using Queues (用队列实现栈)
- 栈-Implement Stack using Queues(用队列实现栈)
- LeetCode 225 Implement Stack using Queues(用队列来实现栈)(*)
- [LeetCode-225] Implement Stack using Queues(两个队列实现栈)
- leetcode之Implement Stack using Queues
- leetcode之Implement Stack using Queues
- leetcode之Implement Stack Using Queues
- [leetcode] 225.Implement Stack using Queues
- UNION-FIND算法
- Android Studio中使用git
- python yeild浅析
- Sql Server 修改表所属用户
- WWDC 2016 Session笔记
- LeetCode学习之-225. 利用队列实现堆栈(Implement Stack using Queues)
- [tomcat] java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor 解决
- [Qt笔记]设置VS2015下的应用工程图标
- 【R和Python对比】matplotlib和ggplot(二)
- 转载CSDN文章的方法
- mysql索引
- WWDC 2015 Session笔记
- Android-25种开源炫酷动画框架
- 超实用的Chrome 控制台实用指南