当前位置:网站首页>5. < tag stack and general problems > supplement: lt.946 Verify the stack sequence (the same as the push in and pop-up sequence of offer 31. stack)
5. < tag stack and general problems > supplement: lt.946 Verify the stack sequence (the same as the push in and pop-up sequence of offer 31. stack)
2022-06-26 04:54:00 【Caicai's big data development path】
lt.946. Verify stack sequence
[ Case needs ]

[ Thought analysis ]

[ Code implementation ]
class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
//pushed First out of the stack , encounter poped The same elements of , Then take it. pop Full stack ;
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();
}
}
The specific problem solution : Am I
边栏推荐
猜你喜欢

记录一次循环引用的问题

torchvision_transform(图像增强)

Motivational skills for achieving goals

一个从坟墓里爬出的公司

A new paradigm for large model application: unified feature representation optimization (UFO)

1.12 learning summary

为什么许多shopify独立站卖家都在用聊天机器人?一分钟读懂行业秘密!

Image translation /gan:unsupervised image-to-image translation with self attention networks

ROS notes (07) - Implementation of client and server

Dbeaver installation and configuration of offline driver
随机推荐
Simple application of KMP
Use of better scroll
2022.2.16
PHP get mobile number operator
1.17 learning summary
DBeaver 安装及配置离线驱动
Hash problem
Multipass Chinese document - share data with instances
Problem follow up - PIP source change
[H5 development] 01 take you to experience H5 development from a simple page ~ the whole page implementation process from static page to interface adjustment manual teaching
22.2.8
What is the best way to store chat messages in a database? [Close] - best way to store chat messages in a database? [closed]
Nabicat连接:本地Mysql&&云服务Mysql以及报错
Introduction to classification data cotegory and properties and methods of common APIs
2.< tag-动态规划和常规问题>lt.343. 整数拆分
1.24 learning summary
Basic query
torchvision_ Transform (image enhancement)
Method of saving pictures in wechat applet
YOLOv5-6.0的一些参数设置和特征图可视化
