当前位置:网站首页>LeetCode 255. 验证前序遍历序列二叉搜索树*
LeetCode 255. 验证前序遍历序列二叉搜索树*
2022-06-10 17:02:00 【暮雨林钟】
具体思路:
单调栈经典;
如果用左右子树递归判断,会爆;
具体代码:
class Solution {
public:
bool verifyPreorder(vector<int>& preorder) {
stack<int>st;
int minx=INT_MIN;
preorder.push_back(INT_MAX);
for(auto& val:preorder){
if(val<minx)
return false;
while(!st.empty()&&val>st.top()){
minx=st.top();
st.pop();
}
st.push(val);
}
return true;
}
};
边栏推荐
- 元宇宙的定义和 7 大无限特征
- 仅需三步学会使用低代码ThingJS与森数据DIX数据对接
- Summary of vim common commands
- 当v-if和v-for需要同时使用的时候
- How will you integrate into the $20trillion "project economy" in five years
- C#_串口通信项目
- It has become a unicorn since its establishment one year ago. Tencent didi is the "backer". This year's new unicorn is not simple
- matplotlib plt. Specific usage of text() - labeling points in a drawing
- One of the Taobao short video pit avoidance Guide Series -- thoroughly understand Taobao short video
- Overseas data centers need to be prepared for unpredictable disasters
猜你喜欢

Nacos configuration management

牛客网:两数之和

线上交流丨技能网络:解决多任务多模态问题的稀疏模型(青源Talk第19期 唐都钰)

Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue

Internet enterprises and chips

Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue

基于PHP+Web+Mysql的在线问卷调查系统

MMdetection之build_optimizer模块解读

Feign based remote call

THE LOTTERY TICKET HYPOTHESIS: FINDING SPARSE, TRAINABLE NEURAL NETWORKS论文笔记
随机推荐
Graduation season: to you
com. netflix. client. ClientException: Load balancer does not have available server for client: userser
企鹅电竞停步,虎牙也难行
Swift 3pThread tool Promise Pipeline Master/Slave Serial Thread confinement Serial queue
Web3 is the most complete money making secret script. Just read this one
Feign based remote call
Snabbdom virtual DOM (I)
Leetcode String to integer(Atoi)
Gateway服务网关
well! One new star, please look over | elder martial brother and elder martial sister say
蓝桥杯_挑选子串_组合数学_乘法原理_ / 尺取法
mapbox-gl开发教程(十一):加载线图层
每日一题-1287. 有序数组中出现次数超过25%的元素
力扣 20. 有效的括号
Mysql database implementation setting field length
当v-if和v-for需要同时使用的时候
com.netflix.client.ClientException: Load balancer does not have available server for client: userser
Draw confusion matrix
【抬杠C#】如何实现接口的base调用
Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)