代码如下:

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. 一模 (4) day1

    第一题: 题目大意:给出N个人之间转账的手续X%,求出A转给B至少要多少钱才能使B得到100元.结果保留8位小数:N<=2000 解题过程: 1.很容易看出这题的图论模型,每条边的权值就是(1- ...

  2. 解决JavaScript中使用$.ajax方式提交数组参数

    一般的,可能有些人在一个参数有多个值的情况下,可能以某个字符分隔的形式传递,比如页面上有多个checkbox: $.ajax{ url:"xxxx", data:{ p: &quo ...

  3. Android 微信分享图文资料

    上个项目做Android的微信分享,需要分享的内容有图片有文字,看了微信分享的SDK,貌似没有这个API,在网上搜了好久,总算找到解决方法了,直接上代码: public void sendReq(Co ...

  4. Unity优化之减少Drawcall

    简单来说,Drawcall就是屏幕渲染一次所需要的开销,为了较少消耗,提高性能,一般有以下几种方法. 一: 批处理 1.动态批处理 如果动态物体共用着相同的材质,那么Unity会自动对这些物体进行批处 ...

  5. Quartz 2D--长方形和线条绘图

    今天原本想模仿2048 游戏的. 但是在设计背景环境时,涉及到绘图的知识!于是就开始对绘图进行了一翻学习. 若想自己绘图必须 写自己的View(继承UICView):然后重写UIView 中的 dra ...

  6. SQL Server 2008 定时作业的制定(SQL2005参考此方法) 转

    --  Author : htl258(Tony)--  Date   : 2010-04-29 19:07:45--  Version:Microsoft SQL Server 2008 (RTM) ...

  7. php中遍历二维数组并以表格的形式输出

    一.索引数组 <?php //使用array()语句结构将联系人列表中所有数据声明为一个二维数组,默认下标是顺序数字索引 $contact1 = array( //定义外层数组 array(1, ...

  8. 单例模式简单解析--Singleton 单例模式(懒汉方式和饿汉方式)

    单例模式的概念: 单例模式的意思就是只有一个实例.单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例.这个类称为单例类. 关键点: 1)一个类只有一个实例       这是最基本 ...

  9. STM32串口USART1的使用方法

    前言: 通用同步异步收发器(USART)提供了一种灵活的方法来与使用工业标准NR 异步串行数据格式的外部设备之间进行全双工数据交换. USART利用分数波特率发生器提供宽范围的   波特率选择,支持同 ...

  10. select multiple images in Android Gallery

    http://stackoverflow.com/questions/18520976/all-properties-of-intent-putextra-to-crop-image-in-andro ...