【leetcode❤python】232. Implement Queue using Stacks
#-*- coding: UTF-8 -*-
#双栈法
class Queue(object):
def __init__(self):
"""
initialize your data structure here.
"""
self.inStack=[]
self.outStack=[]
def push(self, x):
"""
:type x: int
:rtype: nothing
"""
self.inStack.append(x)
def pop(self):
"""
:rtype: nothing
"""
self.peek()
self.outStack.pop()
def peek(self):
"""
:rtype: int
"""
if not self.outStack:
while self.inStack:
self.outStack.append(self.inStack.pop())
return self.outStack[-1]
def empty(self):
"""
:rtype: bool
"""
return True if (len(self.inStack)+len(self.outStack))==0 else False
最新文章
- 剖析并利用Visual Studio Code在Mac上编译、调试c#程序
- ibatis 和 mybatis
- c语言 如何判断是不是 可显字符
- Invoke-Express 执行多个批处理命令的函数
- HDU 5044 TREE
- 主流的phpcms分析
- Tomcat下work文件夹的作用
- [BZOJ 1026] [SCOI 2009] Windy数 【数位DP】
- tmux centos 6.3
- C语言_数字排列顺序
- 【Alpha】第七次Daily Scrum Meeting
- NHibernate3剖析:Configuration篇之SessionFactory lambda配置
- 如何使用Git提高研发团队工作效率?
- Weex小笔记(自己理解,有错请指正)
- UART中的硬件流控RTS与CTS DTR DSR DTE设备和DCE设备【转】
- 莫队算法 [国家集训队]小Z的袜子
- AngularJS实战之filter的使用二
- Windows网络命令
- 在weblogic上配置数据源
- winform 中 MessageBox 用法大全
热门文章
- cometd使用-bayeux协议(读法:贝叶)
- 《OpenGL着色语言》理解点记录三
- How to change Jenkins default folder on Windows?
- MapReduce之Mapper类,Reducer类中的函数(转载)
- spring的定时任务
- JSP页面跳转方式
- oracle 定时备份
- Hive文件格式
- git 本地分支与远程分支关联的一种方法
- Android Studio解决unspecified on project app resolves to an APK archive which is not supported