Login
Register
Problem list
Online status
RockyChen0205
:
2023-11-10 17:10:10
#include
#include
#define size0 10000 #define size1 10000 #define size2 10000 using namespace std; int pre[size0]; int post[size1]; int mp[size2]; int preHead; int postHead; struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(nullptr) {} TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} }; TreeNode* build(int pl,int pr, int il,int ir){ TreeNode* root = new TreeNode(pre[pl]); int k=mp[root->val]; if(k>il) root->left=build(pl+1,k-il+pl,il,k-1); if(k
right=build(k-il+pl+1,pr,k+1,ir); return root; } void postOrder(TreeNode* root,vector
& result){ if(root==nullptr) return; postOrder(root->left,result); postOrder(root->right,result); result.push_back(root->val); return ; } int main(){ int n; cin>>n; vector
> result(n); for(int i=0;i
>preHead; for(int j=1;j<=preHead;j++){ cin>>pre[j]; } cin>>postHead; for(int x=1;x<=postHead;x++){ cin>>post[x]; mp[post[x]]=x; } TreeNode* root=build(1,preHead,1,postHead); postOrder(root,result[i]); } for(int i=0;i
Edward
:
2022-12-04 16:28:32
求教,此题一直ac不了,显示是runtime error或者 memory exceeded
Post Your Comment