当前位置:网站首页>Sword finger offer day 1 stack and queue (simple)
Sword finger offer day 1 stack and queue (simple)
2022-06-25 12:59:00 【Lingtree】
import java.util.Stack;
class CQueue {
Stack<Integer> a;
Stack<Integer> b;
public CQueue() {
a = new Stack<Integer>();
b = new Stack<Integer>();
}
public void appendTail(int value) {
a.push(value);
}
public int deleteHead() {
if(b.empty()) {
while(!a.empty()){
b.push(a.pop());
}
}
if(b.empty()){
return -1;
}
else{
return b.pop();
}
}
}
/**
* Your CQueue object will be instantiated and called as such:
* CQueue obj = new CQueue();
* obj.appendTail(value);
* int param_2 = obj.deleteHead();
*/
import java.util.Stack;
public class MinStack {
Stack<Integer> a;
Stack<Integer> b;
/** initialize your data structure here. */
public MinStack() {
a = new Stack<Integer>();
b = new Stack<Integer>();
}
public void push(int x) {
a.push(x);
if(b.empty() || b.peek() >= x) {
b.push(x);
}
}
public void pop() {
int t = a.pop();
if(t == b.peek()) {
int k = b.pop();
}
}
public int top() {
return a.peek();
}
public int min() {
int pos = b.size() - 1;
return b.peek();
}
}边栏推荐
猜你喜欢

@Scheduled implementation of scheduled tasks (concurrent execution of multiple scheduled tasks)

剑指 Offer II 029. 排序的循环链表
![[machine learning] parameter learning and gradient descent](/img/28/bb0a66b5f0702c995ca9cd7546b678.jpg)
[machine learning] parameter learning and gradient descent
![[machine learning] model and cost function](/img/64/dc7677a3743eb8d060b7b1ecc9aa79.jpg)
[machine learning] model and cost function

又是被Visdom搞崩溃的一夜

Connect with the flight book and obtain the user information according to the userid

How to implement a high-performance load balancing architecture?

剑指Offer 第 2 天链表(简单)
![[flask tutorial] flask development foundation and introduction](/img/c4/fb80fbe6b563e3b304d59623ef6465.jpg)
[flask tutorial] flask development foundation and introduction

【AI助力科研】loss曲线傻瓜式绘制
随机推荐
20220620 interview reply
[data visualization] 360 ° teaching you how to comprehensively learn visualization - Part 1
mysql导入导出数据到excel表日期出现问题
STM32 在flash中存储float数据
深圳民太安智能二面_秋招第一份offer
Render values to corresponding text
Lexical trap
5 kinds of viewer for browser
[flask tutorial] flask development foundation and introduction
Reload cuda/cudnn/pytorch
汇编标志位相关知识点(连)
美创入选“2022 CCIA中国网络安全竞争力50强”榜单
Django框架——缓存、信号、跨站请求伪造、 跨域问题、cookie-session-token
Resolution of PPT paper drawing
利用cmd(命令提示符)安装mysql&&配置环境
You can't specify target table 'xxx' for update in from clause
2021-09-22
Talk about 11 key techniques of high availability
[AI helps scientific research] fool drawing of loss curve
Qt显示FFmpeg解码的图片