当前位置:网站首页>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();
}
}
具体题解: 点我
边栏推荐
- Comment enregistrer une image dans une applet Wechat
- Multipass中文文档-提高挂载性能
- 防撤回测试记录
- LeetCode 94. Middle order traversal of binary tree
- LISP programming language
- Datetime data type ---now() gets the current time, datetime() creation date, performs mathematical operations, and to_ Datetime() converts to date type and extracts various parts of date
- 1.19 learning summary
- 0622-马棕榈跌9%
- Multipass Chinese documents - improve mount performance
- Multipass Chinese document - share data with instances
猜你喜欢
Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview
记录一次循环引用的问题
Wechat applet exits the applet (navigator and api--wx.exitminiprogram)
File upload and security dog
Differences between TCP and UDP
Zhimeng CMS will file a lawsuit against infringing websites
图像翻译/GAN:Unsupervised Image-to-Image Translation with Self-Attention Networks基于自我注意网络的无监督图像到图像的翻译
2022.2.11
Yapi cross domain request plug-in installation
2022.1.24
随机推荐
PSIM software learning ---08 call of C program block
#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
Numpy data input / output
The select option in laravel admin contains a large amount of data
SSH password free login, my server password free login to the other server, the other server password free login to your server
Laravel file stream download file
Problem follow up - PIP source change
Multipass中文文档-远程使用Multipass
1.11 learning summary
1.17 learning summary
Laravel uses phpword to generate word documents
File upload and security dog
Selection of programming language
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
2022.2.11
LISP programming language
2022.2.17
Nabicat连接:本地Mysql&&云服务Mysql以及报错
NVM installation and use and NPM package installation failure record
numpy 索引及切片