【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
【leetcode❤python】232. Implement Queue using Stacks的更多相关文章
- 【LeetCode】232. Implement Queue using Stacks 解题报告(Python & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Python解法 Java解法 日期 [LeetCo ...
- 【一天一道LeetCode】#232. Implement Queue using Stacks
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Impleme ...
- 【LeetCode】232. Implement Queue using Stacks
题目: Implement the following operations of a queue using stacks. push(x) -- Push element x to the bac ...
- 【leetcode❤python】 28. Implement strStr()
#-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object): def strStr(se ...
- 【leetcode❤python】 225. Implement Stack using Queues
#-*- coding: UTF-8 -*-class Stack(object): def __init__(self): """ i ...
- leetcode 155. Min Stack 、232. Implement Queue using Stacks 、225. Implement Stack using Queues
155. Min Stack class MinStack { public: /** initialize your data structure here. */ MinStack() { } v ...
- Leetcode 232 Implement Queue using Stacks 和 231 Power of Two
1. 232 Implement Queue using Stacks 1.1 问题描写叙述 使用栈模拟实现队列.模拟实现例如以下操作: push(x). 将元素x放入队尾. pop(). 移除队首元 ...
- 232. Implement Queue using Stacks,225. Implement Stack using Queues
232. Implement Queue using Stacks Total Accepted: 27024 Total Submissions: 79793 Difficulty: Easy Im ...
- [LeetCode] 232. Implement Queue using Stacks 用栈来实现队列
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
随机推荐
- Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别
Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别 时间 2012-12-19 20:30:12 CSDN博客原文 http://blog.cs ...
- [javascript] ajaxfileupload.js 跨域上传文件
原文地址: http://www.ueffort.com/jqueryajaxfileupload-js-duo-wen-jian-shang-chuan-chuan-zhi-kua-yu/ 跨域 这 ...
- 常用的DC插头公头的尺寸
2.0*0.6mm:这种应该是用在诺基亚黑白屏那种手机上的充电插头 2.5*0.7mm:这种不知用在哪里 3.5*1.35mm:应该是以前那种小型的磁带机放音机上用的 4.0*1.7mm:已知 ora ...
- RobotFrameWork接口报文测试-----(三)demo的加强版(数据驱动测试)
在上一篇RobotFrameWork接口报文测试-----(二)demo的升级版基础上,将接口的xml的格式保存在xml文件中,然后程序如果增加一个接口,在xml文件里添加即可,无需修改自动化测试里的 ...
- netsh修改IP及DNS
netsh interface ip show addresses 显示当前IP netsh interface ip show dns 显示当前DNS netsh interf ...
- Char、AnsiChar、WideChar、PChar、PAnsiChar、PWideChar 的用法
varc: Char; {Char 类型的取值范围是: #0..#255, 用十六进制表示是: #$0..#$FF}begin{用十进制方式赋值:}c := #65;ShowMessage(c); ...
- android 中activity调用本地service中的方法。
1.自定义一个接口,暴露服务中的方法 public interface IService { /**服务中对外暴露的方法 */ void methodInService();} 2.自定一 ...
- Java中删除指定文件夹文件夹下面有内容也删除使用递归方案
import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java ...
- Yeoman
安装Yeoman之前,确认安装好Node.js和npm. sudo npm install --global yo 然后查看软件版本 yo --version && bower --v ...
- SpringMVC项目,启动项目怎么总是报找不到log4j.properties文件
具体操作:右键项目---->properties--->Java Build Path--->source--->Add Folder --->选择log4.proper ...