#-*- coding: UTF-8 -*-
class Stack(object):
    def __init__(self):
        """
        initialize your data structure here.
        """
        self.inQueue=[]
        self.outQueue=[]

    def push(self, x):
        """
        :type x: int
        :rtype: nothing
        """
        self.inQueue.append(x)
        
        

    def pop(self):
        """
        :rtype: nothing
        """
        i=0
        while i<len(self.inQueue)-1:
            self.outQueue.append(self.inQueue[i])
            i+=1
        self.inQueue=self.outQueue
        self.outQueue=[]
       
       
        
    def top(self):
        """
        :rtype: int
        """
        tmpQueue=self.inQueue
        i=0;
        while i<(len(self.inQueue)-1):
            self.outQueue.append(self.inQueue[i])
            i+=1
        
        res=[i for i in self.inQueue if i not in self.outQueue]
        self.outQueue=[]
        return res[0]
        

    def empty(self):
        """
        :rtype: bool
        """
        return True if (len(self.inQueue))==0 else False

sol=Stack()
sol.push(1)
sol.push(2)
print sol.top()
sol.pop()
print sol.top()
sol.pop()
print sol.empty()

【leetcode❤python】 225. Implement Stack using Queues的更多相关文章

  1. 【LeetCode】225. Implement Stack using Queues 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. 【一天一道LeetCode】#225. Implement Stack using Queues

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Impleme ...

  3. 【LeetCode】225. Implement Stack using Queues

    题目: Implement the following operations of a stack using queues. push(x) -- Push element x onto stack ...

  4. 【leetcode❤python】 155. Min Stack

    #-*- coding: UTF-8 -*- class MinStack(object):    def __init__(self):        """      ...

  5. 【easy】225. Implement Stack using Queues

    用队列实现栈.这个实现方法十分的简单,就是在push这一步的时候直接变成逆序. class MyStack { private: queue<int> q; queue<int> ...

  6. 【leetcode❤python】 28. Implement strStr()

    #-*- coding: UTF-8 -*- #题意:大海捞刀,在长字符串中找出短字符串#AC源码:滑动窗口双指针的方法class Solution(object):    def strStr(se ...

  7. 【leetcode❤python】232. Implement Queue using Stacks

    #-*- coding: UTF-8 -*-#双栈法class Queue(object):    def __init__(self):        """      ...

  8. 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 ...

  9. 232. Implement Queue using Stacks,225. Implement Stack using Queues

    232. Implement Queue using Stacks Total Accepted: 27024 Total Submissions: 79793 Difficulty: Easy Im ...

随机推荐

  1. 学Python后到底能干什么?

    Python是一种什么语言? Python是一种计算机程序设计语言.你可能已经听说过很多种流行的编程语言,比如非常难学的C语言,非常流行的Java语言,适合初学者的Basic语言,适合网页编程的Jav ...

  2. java编程思想恶心的enum状态机示例

    下面是一个包装输入的类 package test; import java.util.Random; public enum Input { NICKEL(5) , DIME(10) , QUARTE ...

  3. HDU 1828 Picture(线段树扫描线求周长)

    Picture Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  4. swift 2.x学习笔记(一)

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #008400 } p.p2 { margin: 0.0px 0. ...

  5. RabbitMQ使用相关笔记

    #运行各示例脚本 [1] 1. 下载各语言的示例代码 https://github.com/rabbitmq/rabbitmq-tutorials 2. 安装pip,命令"yum -y in ...

  6. 一些IT中的工具介绍【转】

      1. 史上最全github使用方法:github入门到精通 2. Git教程 3. GIT与GitHub使用简介 简单来说,git是一种版本控制系统.跟svn.cvs是同级的概念.github是一 ...

  7. Web前端工程师成长之路

    一.何为Web前端工程师?        前端工程师,也叫Web前端开发工程师.他是随着web发展,细分出来的行业.Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript/D ...

  8. Bootstrap modal被sliverlight掩盖。

    Bootstrap中的modal被silverlight遮挡了,解决方案: <object id='xx'....> ... <param name="windowless ...

  9. winform 对话框、打印框

    winform 对话框控件 1.打开文件对话框(OpenFileDialog) 2.保存文件对话框(SaveFileDialog) 3.字体对话框(FontDialog) 4.颜色对话框(ColorD ...

  10. window.event

    e = e || window.event是我们在做事件处理时候区分IE和其他浏览器事件对象时常用的写法.但是这行兼容性代码有没有必要出现在所有的事件句柄中呢?标准事件调用方式需要这行代码吗?下边我们 ...