代码如下:

class MyStack {
// Push element x onto stack.
Queue<Integer> queue=new ArrayDeque<>(); public void push(int x) {
Queue<Integer> p=new ArrayDeque<>();
int c=queue.size();
while(c!=)
{
p.offer(queue.peek());
queue.remove();
c--;
}
queue.offer(x);
int d=p.size();
while(d!=)
{
queue.offer(p.peek());
p.remove();
d--;
} } // Removes the element on top of the stack.
public void pop() {
queue.remove();
} // Get the top element.
public int top() {
return queue.peek();
} // Return whether the stack is empty.
public boolean empty() {
if(queue.size()==)
return true;
return false;
}
}

225. Implement Stack using Queues的更多相关文章

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

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

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

  3. Java for LeetCode 225 Implement Stack using Queues

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

  4. (easy)LeetCode 225.Implement Stack using Queues

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

  5. Leetcode 225 Implement Stack using Queues

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

  6. Java [Leetcode 225]Implement Stack using Queues

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

  7. 【LeetCode】225. Implement Stack using Queues

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

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

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

  9. LeetCode 225 Implement Stack using Queues(用队列来实现栈)(*)

    翻译 用队列来实现栈的例如以下操作. push(x) -- 将元素x加入进栈 pop() -- 从栈顶移除元素 top() -- 返回栈顶元素 empty() -- 返回栈是否为空 注意: 你必须使用 ...

  10. 225 Implement Stack using Queues 队列实现栈

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

随机推荐

  1. Expression<Func<T, bool>>

    public static Expression<Func<T, bool>> True<T>() { return f => true; } public ...

  2. Halcon 10.0:Hobject图像转CBitmap

    void HImage2CBitmap(Hobject pImage,CBitmap *wImage) { char lpcsType[MAX_STRING]; Hlong lPointer,widt ...

  3. 快排找第k大模板

    int get_kth(int l,int r) { if (l==r) return a[r]; ]; while (i<j) { while (a[i]<mid) i++; while ...

  4. 使用rgba色实现背景色透明

    父元素css属性:background-color: #000;  background: rgba(0,0,0,.5); //现代浏览器属性,使用rgba色实现透明,对子属性不继承  filter: ...

  5. how to reset mac root password

    Reset 10.5 Leopard & 10.6 Snow Leopard password Power on or restart your Mac. At the chime (or g ...

  6. windows命令行及批处理文件小结

    1.命令Shell概述(Command shell overview): The command shell is a separate software program that provides ...

  7. Android安全之WebViewUXSS漏洞

    Android安全 WebView UXSS app开发 漏洞分析 移动安全 0X01 前言 XSS是我们比较熟悉的一种攻击方式,包括存储型XSS.反射型XSS.DOM XSS等,但UXSS(通用型X ...

  8. 安装Windows Metasploit Framework

    Installing the Metasploit Framework on Windows 1. Visit http://windows.metasploit.com/metasploitfram ...

  9. jsp MVC学习笔记

    Model层: 四个包: com.maker.bean存放数据库里面的字段信息. package com.maker.bean; public class User { private String ...

  10. UIkit框架之UItableview

    1.继承链:UIScrrollView:UIview:UIresponder:NSObject 2.创建实例的时候首先需要确定table的类型 3.一个tableview对象必须要有一个数据源和一个委 ...