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 ...
随机推荐
- 使用QQ邮箱SMTP服务的javamail配置
最近做一个小项目要用到JAVA的邮箱的发送功能.遇到一些坑这里记录分享一下:QQ群交流:697028234 1.QQ邮箱一定要设置开通SMTP/POP这项.并生成授权码. 2.用MAVEN生成一个QU ...
- Python3 字符串(七)
字符串是 Python 中最常用的数据类型.我们可以使用引号( ' 或 " )来创建字符串. 创建字符串很简单,只要为变量分配一个值即可. python中单引号和双引号使用完全相同. 使用三 ...
- SharePoint 2013的100个新功能之网站管理(三)
一:跨网站发布 跨网站发布是SharePoint 2013的一个新功能,可以使用户跨网站集.Web应用程序甚至是场重用内容.该功能叫做跨网站发布功能.用户可以使用该功能在SharePoint 2013 ...
- 修改Oracle归档日志方法
修改Oracle归档日志的方法 Oracle默认安装的归档日志只有50M,在做大量操作的时候会经常切换日志文件,造成性能问题,下面是具体操作方法 1. 下面是查看现有归档日志大小: SQL> ...
- Zabbix监控TCP status
监控原理 ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' LAST-ACK 5ESTAB 348FIN-WAIT-1 ...
- 量化投资策略:常见的几种Python回测框架(库)
量化投资策略:常见的几种Python回测框架(库) 原文地址:http://blog.csdn.net/lawme/article/details/51454237 本文章为转载文章.这段时间在研究量 ...
- 【传输协议】HttpClient基本使用
最近工作中是做了一个handoop的hdfs系统的文件浏览器的功能,是利用webhdfs提供的rest api来访问hdfs来与hdfs进行交互的,其中大量使用HttpClient,之前一直很忙,没什 ...
- ES6必知必会 (八)—— async 函数
async 函数 1.ES2017 标准引入了 async 函数,它是对 Generator 函数的改进 , 我们先看一个读取文件的例子: Generator 写法是这样的 : var fs = re ...
- harbor rest api 转graphql api
原理 实际上就是使用graphql 中的binding,首先基于swagger api 进行schema 生成,后边就是 使用binding 进行graphql 请求api 转换为rest api 请 ...
- FastAdmin 环境变量 env 配置
FastAdmin 环境变量 env 配置 目前 FastAdmin 支持环境变量 env 配置. 目前支持以下环境变量 app.debug app.trace database.type datab ...