leetcode232
public class MyQueue
{
Stack<int> S = new Stack<int>();
/** Initialize your data structure here. */
public MyQueue()
{ } /** Push element x to the back of queue. */
public void Push(int x)
{
S.Push(x);
} /** Removes the element from in front of queue and returns that element. */
public int Pop()
{
List<int> list = new List<int>();
var x = -;
while (S.Count > )
{
x = S.Pop();
list.Add(x);
} for (int i = list.Count - ; i >= ; i--)
{
S.Push(list[i]);
} return x;
} /** Get the front element. */
public int Peek()
{
if (S.Count > )
{
return S.ElementAt(S.Count - );
}
else
{
return -;
}
} /** Returns whether the queue is empty. */
public bool Empty()
{
return S.Count == ;
}
} /**
* Your MyQueue object will be instantiated and called as such:
* MyQueue obj = new MyQueue();
* obj.Push(x);
* int param_2 = obj.Pop();
* int param_3 = obj.Peek();
* bool param_4 = obj.Empty();
*/
https://leetcode.com/problems/implement-queue-using-stacks/#/description
leetcode232的更多相关文章
- [Swift]LeetCode232. 用栈实现队列 | Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- 【LeetCode232】 Implement Queue using Stacks★
1.题目描述 2.思路 思路简单,这里用一个图来举例说明: 3.java代码 public class MyQueue { Stack<Integer> stack1=new Stack& ...
- LeetCode232:Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) – Push element x to the back of ...
- LeetCode232 Implement Queue using Stacks Java 题解
题目: Implement the following operations of a queue using stacks. push(x) -- Push element x to the bac ...
- LeetCode232 用栈实现队列
使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从队列首部移除元素. peek() -- 返回队列首部的元素. empty() -- 返回队列是否为空. ...
- 面试之leetcode20堆栈-字符串括号匹配,队列实现栈
1 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合.左括号必须以正确的顺序闭合.注意空字符串可被认 ...
- LeetCode-Stack-Easy
简单题 1. 有效的括号(leetcode-20) 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 1. 左括号必须用相同类型的右括 ...
- LeetCode通关:栈和队列六连,匹配问题有绝招
刷题路线参考: https://github.com/chefyuan/algorithm-base https://github.com/youngyangyang04/leetcode-maste ...
随机推荐
- java反射教程
什么是反射,为什么它是有用的,以及如何使用它? 1.什么是反射? “反射通常是JVM中运行的程序需要检测和修改运行时程序的行为的一种能力.”这个概念通常与内省(Introspection)混淆.以下是 ...
- CC工具列表
QuasarRAT Adwind Adzok Arcom Babylon Blacknix Blue Banana Bozok Coringa DarkComet DRAT Gh0st Huige ...
- 《BAT前端进阶[师徒班]》学习总结
这是一个培训课 是的,这是一个面向中级前端的培训班,但明显跟传统的填鸭式培训班不太一样.这边的老师都是大牛这是毫无疑问的,而且都是一线开发人员.而且课程一开始就说明了面向了是有1-3年有工作经验的前端 ...
- 09_Git patch(补丁)操作
Git打补丁,补丁操作一般在多人开发时才会用到,单人本地开发一般用不到,没必要. 应用场景举例: 我把我的更改打成一个补丁发给你,你来合并到你的代码中 或者,在家里电脑开发提交后,打一个补丁,拿到 ...
- Linux DMA Engine framework(2)_功能介绍及解接口分析
http://www.wowotech.net/linux_kenrel/dma_engine_api.html 补充 http://www.zhimengzhe.com/linux/259646.h ...
- (转)Fiddler教程(Web调试工具)
转载地址:写得很不错的fildder教程 http://kb.cnblogs.com/page/130367/ Fiddler的基本介绍 Fiddler的官方网站: www.fiddler2.c ...
- UML类图中的各种箭头代表的含义(转自:http://www.cnblogs.com/damsoft/archive/2016/10/24/5993602.html)
1.UML简介Unified Modeling Language (UML)又称统一建模语言或标准建模语言. 简单说就是以图形方式表现模型,根据不同模型进行分类,在UML 2.0中有13种图,以下是他 ...
- Python 高性能并行计算之 mpi4py
MPI 和 MPI4PY 的搭建上一篇文章已经介绍,这里面介绍一些基本用法. mpi4py 的 helloworld from mpi4py import MPI print(&quo ...
- ieee80211 phy1: Failed to select rate control algorithm
/************************************************************************ * ieee80211 phy1: Failed t ...
- 控制led灯并显示自己的数值
前提是有led.jar包封装好了东西 1.并设置好led灯的模式并打开串口. 2.在布局中创建一个EditText ,Button.并利用-.getText.toString().trim(); 来获 ...