1138. Postorder Traversal (25)
来源:互联网 发布:淘宝优惠券返利网 编辑:程序博客网 时间:2024/05/29 18:32
#include <bits/stdc++.h>using namespace std;int pre[50002],ino[50002],ans;void solve(int preL,int preR,int inoL,int inoR){ if(preL>preR)return; int idx=inoL,pdx=preL; int root=pre[preL]; while(root!=ino[idx])++idx,++pdx; ans=root; if(preL+1<=pdx) solve(preL+1,pdx,inoL,idx-1); else solve(pdx+1,preR,idx+1,inoR);}int main(){ int n; cin>>n; for(int i=0;i<n;++i) scanf("%d",&pre[i]); for(int i=0;i<n;++i) scanf("%d",&ino[i]); solve(0,n-1,0,n-1); cout<<ans; return 0;}
阅读全文
0 0
- 1138. Postorder Traversal (25)
- 1138. Postorder Traversal (25)
- 1138. Postorder Traversal (25) 二叉树前序中须转后序
- 1138. Postorder Traversal (25)(前序中序,求后序)
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- Binary Tree Postorder Traversal
- spring boot 错误处理
- 各种常见邮箱端口
- 使用canvas 做动态时钟特效
- 事件无法在命名空间里激活错误的解决
- 干货 | 机器学习集成算法:XGBoost模型构造
- 1138. Postorder Traversal (25)
- 连载 | 理解线性代数04 利用行列式求解 Ax = b
- HDU-1711 Number Sequence kmp算法
- ImageLoader的使用
- Reflection2017.12.15
- 一张图看明白Git的四个区五种状态
- VPS中shadowsock配置SOCK5服务器
- Week04_day03 IO流(下) 字符流、缓冲流、转换流
- HashMap和ConcurrentHashMap原理解读(基于JDK1.7)