《非常简单的一道题目》
就,如果你懂得关于树的知识,那么就确实就是很简单。题目都没有很难的,你觉得难是因为你的知识点不熟练。
满分代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e2+10;
int in[N],pre[N],n;
struct Node{
int l,r;
}Tree[N];
int build(int l1,int r1,int l2,int r2){
//l1-r1中序遍历,l2-r2先序遍历
if(l1 > r1 || l2 > r2) return 0;
int p = l1;
while(in[p] != pre[l2]) p++;
int len = p - l1;
int rt = pre[l2];
Tree[rt].l = build(l1,p-1,l2+1,l2 + len);
Tree[rt].r = build(p+