当前位置:网站首页>5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
5. <tag-栈和常规问题>补充: lt.946. 验证栈序列(同剑指 Offer 31. 栈的压入、弹出序列)
2022-06-26 04:49:00 【菜菜的大数据开发之路】
lt.946. 验证栈序列
[案例需求]

[思路分析]

[代码实现]
class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
//pushed先出栈, 遇到poped的相同元素一起出栈, 然后再把pop完全出栈;
Deque<Integer> stack = new LinkedList<>();
int i = 0;
for(int num : pushed){
stack.push(num);
while(!stack.isEmpty() && stack.peek() == popped[i]){
stack.pop();
++i;
}
}
return stack.isEmpty();
}
}
具体题解: 点我
边栏推荐
猜你喜欢

Database design (3): database maintenance and optimization

Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview

文件上传与安全狗

【Latex】错误类型总结(持更)

Sixtool- source code of multi-functional and all in one generation hanging assistant

0622 horse palm fell 9%

Use of better scroll

2021-02-07

torchvision_transform(图像增强)

Wechat applet exits the applet (navigator and api--wx.exitminiprogram)
随机推荐
基础查询
Thinkphp6 implements a simple lottery system
1.17 learning summary
Anti withdrawal test record
Performance test comparison between PHP framework jsnpp and thinkphp6
NVM installation and use and NPM package installation failure record
2.9 learning summary
dijkstra
Multipass中文文档-与实例共享数据
Svn error command revert error previous operation has not finished; run ‘ cleanup‘ if
Text horizontal alignment attribute text align and element vertical alignment attribute vertical align
Multipass Chinese document - remote use of multipass
Interpretation of yolov5 training results
0622 horse palm fell 9%
1.20 learning summary
YOLOV5训练结果的解释
BACK-OFF RESTARTING FAILED CONTAINER 的解决方法
Using Matplotlib to add an external image at the canvas level
Some parameter settings and feature graph visualization of yolov5-6.0
Multipass Chinese document - share data with instances
