当前位置:网站首页>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();
}
}
具体题解: 点我
边栏推荐
猜你喜欢
随机推荐
2022 talent strategic transformation under the development trend of digital economy
#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
MySql如何删除所有多余的重复数据
0622 horse palm fell 9%
Install Damon database
Numpy data input / output
Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview
"Eight hundred"
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
Redis cache message queue
The select option in laravel admin contains a large amount of data
Database design (3): database maintenance and optimization
微信小程序保存图片的方法
Svn correlation
Multipass中文文档-使用Packer打包Multipass镜像
2022.1.24
ROS notes (07) - Implementation of client and server
A troubleshooting of website crash due to high CPU
2.8 learning summary
Multipass Chinese document - remove instance










