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 ...
随机推荐
- 一. Spring框架防XXS跨站攻击
使用 Spring 框架进行 Java Web 开发,可以在 web.xml 文件中设置 HTML encode,在 JSP 文件页面元素 form 中确定实施. web.xml 加上: <co ...
- 快速理解 FastCGI、PHP-CGI、PHP-FPM
你(PHP)去和泰国人(web服务器,如 Apache.Nginx)谈生意 你说中文(PHP代码),他说泰语(C代码),互相听不懂,怎么办?那就都把各自说的话转换成英语(FastCGI 协议)吧. 怎 ...
- Digitalocean+DNSPod搭建Meteor.js博客Telescope.js
1. 什么是Meteor.js 基于Node.js的一个快速开发平台. 简言之,Node.js>Meteor.js 对等于Ruby>Ruby on Rails的关系. 官网:http:// ...
- Work Queues(点对多)
Work Queues(点对多) 多个消费者在同一个消息队列中获取消息的情况.在有些应用当中,消费端接收到消息任务需要长时间的处理,如果等上一个消息处理完成以后再取下一个数据进行处理的话,势必会有一些 ...
- LNMP架构下的nginx、mysql、php的源码安装
一.LNMP的介绍 LNMP就是Linux+Nginx+Mysql+Php这种网站服务架构.Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统,常见版本有:centos.ubun ...
- eclipse加入c标签
在MyEclipse中使用jstl标签只需导读jstl.jar就能使用,但是在Eclipse中还需要一点小套路 步骤: 一.导入jstl.jar 二.导入导入standard.jar 三.在WEB-I ...
- springboot---数据整合篇
本文讲解 Spring Boot 基础下,如何使用 JDBC,配置数据源和通过 JdbcTemplate 编写数据访问. 环境依赖 修改 POM 文件,添加spring-boot-starter-jd ...
- 使用RESTful风格整合springboot+mybatis
说明: 本文是springboot和mybatis的整合,Controller层使用的是RESTful风格,数据连接池使用的是c3p0,通过postman进行测试 项目结构如下: 1.引入pom.xm ...
- WIN 10环境下JDK的安装和环境配置
在做测试的过程中,诸如Selenium.Appium.Macaca.Airtest.RobotFramework.Jmeter等框架或工具都需要用到一样基础的环境JAVA JDK.最近刚好换了电脑,就 ...
- Convex 一道阿姆斯特朗回旋好题
2001年5月8日,阿姆斯特朗(Armstrong, 1929-2013) 教授发明了一种名为“阿姆斯特朗回旋加速喷气式阿姆斯特朗加密”的加密算法,算法从未公开,直至2013阿姆斯特朗教授逝世后,其生 ...