【算法】用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
2024-08-29 22:47:42
public class Solution {
Stack<Integer> stack1 = new Stack<Integer>();
Stack<Integer> stack2 = new Stack<Integer>();
public void push(int node) {
stack1.push(node);
}
public int pop() {
if(stack1.empty()&&stack2.empty()){
throw new RuntimeException("Queue is empty!");
}
if(stack2.empty()){
while(!stack1.empty()){
stack2.push(stack1.pop());
}
}
return stack2.pop();
}
}
最新文章
- .NET平台开源项目速览(2)Compare .NET Objects对象比较组件
- Smooth Mouse
- LINK : fatal error LNK1104: 无法打开文件“gtestd.lib”
- 关于touch事件对于性能的影响
- linux挂载硬盘失败,报错!
- Oracle表连接
- 从APP消息推送所理解的观察者模式
- Java学习之异常处理
- POJ 2991 Crane(线段树+计算几何)
- web端和手机端测试有什么不同
- ZZNU 1993: cots&#39; friends
- (基础篇 走进javaNIO)第一章-java的i/o演进之路
- mysql高级之编程优化
- APICloud |UIChatTools 模块demo
- springMVC控制器,处理器,映射器,适配器
- 最短路径之Bellman-Ford算法
- 关于js特效轮播图练习
- 轻量架构ShuffleNet V2:从理论复杂度到实用设计准则
- git-ftp代码部署方式
- 使用cuteFTP与虚拟机交互文件---安装ftp服务
热门文章
- 本地开发环境伪装成SSL连接的实现
- 吴恩达deepLearning.ai循环神经网络RNN学习笔记_没有复杂数学公式,看图就懂了!!!(理论篇)
- python 实现 跳一跳游戏 代码解析
- ubuntu16.04 自建源
- LVM 逻辑卷 (logica volume manager)
- Spring MVC系列之JDBC Demo(SpringBoot)(七)
- Leetcode:96. 不同的二叉搜索树
- cf1294E
- The server cannot be started because one or more of the ports are invalid. Open the server editor and correct the invalid ports.
- 从零开始一个个人博客 by asp.net core and angular(二)