1138. Postorder Traversal (25)
发布日期:2021-05-04 09:01:54 浏览次数:20 分类:原创文章

本文共 630 字,大约阅读时间需要 2 分钟。

#include <iostream>using namespace std;int pre[50000], ino[50000], res;void getFirstInPos(int preL, int preR, int inoL, int inoR){    if(preL > preR) return;    int e = pre[preL], idx = inoL;    while(e != ino[idx]) ++idx;    res = e;    if(idx == inoL) getFirstInPos(preL + 1, preR, inoL + 1, inoR);    else getFirstInPos(preL + 1, idx - 1 - inoL + preL + 1, inoL, idx - 1);}int main(){    int n;    ios::sync_with_stdio(false);    cin >> n;    for(int i = 0; i < n; ++i){        cin >> pre[i];    }    for(int i = 0; i < n; ++i){        cin >> ino[i];    }    getFirstInPos(0, n-1, 0, n-1);    cout << res << endl;    return 0;}
上一篇:1137. Final Grading (25)
下一篇:1139. First Contact (30)

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年03月22日 22时15分08秒