当前位置:网站首页>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;
}
};
边栏推荐
- Brands are difficult to establish, IPO is difficult, and Chinese tea enterprises are trapped in "tradition"?
- [the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
- The relationship between trees, forests and binary trees
- 嘿!ONES 新星请看过来|师兄师姐说
- flex布局语法
- There is an urgent need to enrich the smart home product line. Can fluorite be crowded on the sweeping robot track?
- 如何运行plink软件--三种方法
- 元宇宙的定义和 7 大无限特征
- 你还在手写TS类型代码吗
- Penguin E-sports stops, and tiger teeth are hard to walk
猜你喜欢

Nacos registry

C#_串口通信项目

Photoshop如何打开、编辑和导出Webp格式图片的方法

软件项目管理 6.10.成本预算

牛客网:表达式求值

Numpy numpy中np.set_printoptions()的用法——控制输出方式

Online communication skill network: a sparse model for solving multi task and multi-modal problems (Qingyuan talk, issue 19, tangduyu)

训练时添加进度条的库--tqdm

树、森林和二叉树的关系

Web3 is the most complete money making secret script. Just read this one
随机推荐
mmdetection之model构建
When V-IF and V-for need to be used at the same time
嘿!ONES 新星请看过来|师兄师姐说
Gateway service gateway
我在做一件很酷的事情
CUDA Programming (I): add two arrays
2022年茶艺师(中级)操作证考试题库及模拟考试
Vim常用命令总结
Draw confusion matrix
[the second revolution of report tools] optimize report structure and improve report operation performance based on SPL language
开源项目 PM 浅谈如何设计官网
为什么宇宙会将最大速度限制在光速
基于DeepFace模型设计的人脸识别软件
【内容共创】第17期 夏日炎炎,有你超甜!参与签约华为云小编,花样礼包总有一款打动你!
Analysis of transfer Refund Scheme in e-commerce industry
聊聊消息中间件(1),AMQP那些事儿
领导提拔你的原因,只有这点最真实,其他都是瞎扯!
numpy——记录
Protocol Gen go grpc 'is not an internal or external command, nor is it a runnable program or batch file
pands pd.DataFrame()函数详细解析