当前位置:网站首页>【剑指 Offer】剑指 Offer 09. 用两个栈实现队列
【剑指 Offer】剑指 Offer 09. 用两个栈实现队列
2022-07-18 20:59:00 【@来杯咖啡】
算法汇总
以下是所有算法汇总,包括GitHub源码地址链接:力扣算法练习汇总(持续更新…)
题目
关键点
1、
2、
代码
1.解体方法
思路
代码
class CQueue {
Stack<Integer> stack1 = new Stack<>();
Stack<Integer> stack2 = new Stack<>();
public CQueue() {
}
public void appendTail(int value) {
stack1.push(value);
}
public int deleteHead() {
if (stack1.isEmpty() && stack2.isEmpty()) {
return -1;
}
if (!stack2.isEmpty()) {
return stack2.pop();
} else {
while (!stack1.isEmpty()) {
stack2.push(stack1.pop());
}
return stack2.pop();
}
}
}
/** * Your CQueue object will be instantiated and called as such: * CQueue obj = new CQueue(); * obj.appendTail(value); * int param_2 = obj.deleteHead(); */
时间和空间复杂度
2.解题方法,如暴力法
思路
代码
时间和空间复杂度
边栏推荐
猜你喜欢
还在羡慕其它平台有跨店满减,其实你也可以!
ERROR: Could not open requirements file: [Errno 2] No such file or directory: ‘requirments.txt’
TDengine 在中天钢铁 GPS、 AIS 调度中的落地
Pycharm configuring Anaconda virtual environment and introduction to common CONDA commands
十分钟生成影视级室内设计效果,红星美凯龙设计云如何升级传统家居行业
Pytoch and drop_ Out (discard method)
Mhchxm ultrafast recovery diode sff1004 parameters, sff1004 characteristics
入职5年的测试工程师-下一步该如何选择方向?
Based on easycv to reproduce Detr and dab-detr, the correct opening method of object query
2022年全国最新消防设施操作员(高级消防设施操作员)模拟试题及答案
随机推荐
黑灰产眼中的NFT:平台嗷嗷待宰,用户送钱上门
这些年我开源的几个小项目
2022.07.17(LC_6121_裁剪数字后查询第 K 小的数字)
C language guessing numbers game
Pytoch and drop_ Out (discard method)
集成电路先进制造技术进展与趋势
ROS2初步:用Topic基本通信
大作业中的新知识
使用Latex排版选择题试卷
查缺补漏C语言:字符串
Evolution of service architecture
Kubernetes introduction practice
2022.07.17 (maximum sum of lc_6164_digits and equal pairs)
C language (high level) dynamic + file address book
Why is mhchxm ultrafast recovery diode sff1604 a frequent customer of switching power supply
Compose中更灵活易用的TextField以及密码输入框
交换机于路由器技术:OSPF单区域配置、OSPF多区域和末梢区域
【云原生】微服务之Feign的介绍与使用
隐藏滚动条但可以滚动
【目标检测】YOLOv5:模型构建解析