
1138 Postorder Traversal (25 point(s))
#include #include using namespace std;
发布日期:2021-05-18 12:17:45
浏览次数:19
分类:精选文章
本文共 613 字,大约阅读时间需要 2 分钟。
#include
const int N = 5e4 + 10;int n, in[N], pre[N];unordered_map<int, int> pos;int l, r;bool s;
int build(int il, int ir, int pl, int pr) {int root = pre[pl];int k = pos[root];if (k > il) {l[root] = build(il, k-1, pl+1, pl+k-il);}if (k < ir) {r[root] = build(k+1, ir, pl+k-il+1, pr);}return root;}
void post(int u) {if (l.count(u)) {post(l[u]);}if (r.count(u)) {post(r[u]);}if (!s) {s = "1";cout << u;}}
int main() {cin >> n;for (int i = 0; i < n; i++) {cin >> pre[i];}for (int i = 0; i < n; i++) {cin >> in[i];pos[in[i]] = i;}int root = build(0, n-1, 0, n-1);post(root);}
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2025年04月29日 17时43分51秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
spring-boot-2.0.3之redis缓存实现,不是你想的那样哦!
2019-03-06
有道云笔记 同步到我的博客园
2019-03-06
李笑来必读书籍整理
2019-03-06
Hadoop(十六)之使用Combiner优化MapReduce
2019-03-06
《机器学习Python实现_10_06_集成学习_boosting_gbdt分类实现》
2019-03-06
CoreCLR源码探索(八) JIT的工作原理(详解篇)
2019-03-06
andriod 开发错误记录
2019-03-07
C语言编译错误列表
2019-03-07
看明白这两种情况,才敢说自己懂跨链! | 喵懂区块链24期
2019-03-07
python中列表 元组 字典 集合的区别
2019-03-07
Android DEX加固方案与原理
2019-03-07
iOS_Runtime3_动态添加方法
2019-03-07
Leetcode第557题---翻转字符串中的单词
2019-03-07
Problem G. The Stones Game【取石子博弈 & 思维】
2019-03-07
Java多线程
2019-03-07
openssl服务器证书操作
2019-03-07
我用wxPython搭建GUI量化系统之最小架构的运行
2019-03-07
我用wxPython搭建GUI量化系统之多只股票走势对比界面
2019-03-07