Skip to content

Commit 6bd54dc

Browse files
Added day27 solution
1 parent 19a08bf commit 6bd54dc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
TreeNode *Tree(vector<int>& in, int x, int y,vector<int>& po,int a,int b){
2+
if(x > y || a > b)return nullptr;
3+
TreeNode *node = new TreeNode(po[b]);
4+
int SI = x;
5+
while(node->val != in[SI])SI++;
6+
node->left = Tree(in,x,SI-1,po,a,a+SI-x-1);
7+
node->right = Tree(in,SI+1,y,po,a+SI-x,b-1);
8+
return node;
9+
}
10+
TreeNode* buildTree(vector<int>& in, vector<int>& po){
11+
return Tree(in,0,in.size()-1,po,0,po.size()-1);
12+
}

0 commit comments

Comments
 (0)