Skip to content

Commit 3610649

Browse files
mah-shamimkovatztopugitbasharul-siddikehafijul233
committed
#1350, #1351 leetcode problems 000889-construct-binary-tree-from-preorder-and-postorder-traversal submissions 1552937068
Co-authored-by: kovatz <[email protected]> Co-authored-by: topugit <[email protected]> Co-authored-by: basharul-siddike <[email protected]> Co-authored-by: hafijul233 <[email protected]>
1 parent 0018596 commit 3610649

File tree

1 file changed

+6
-23
lines changed
  • algorithms/000889-construct-binary-tree-from-preorder-and-postorder-traversal

1 file changed

+6
-23
lines changed

algorithms/000889-construct-binary-tree-from-preorder-and-postorder-traversal/README.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,12 @@ class TreeNode {
6969
* @return TreeNode
7070
*/
7171
function constructFromPrePost($preorder, $postorder) {
72-
if (empty($preorder)) {
73-
return null;
74-
}
75-
$rootVal = $preorder[0];
76-
$root = new TreeNode($rootVal);
77-
$n = count($preorder);
78-
if ($n == 1) {
79-
return $root;
80-
}
81-
$leftVal = $preorder[1];
82-
$leftPostIdx = array_search($leftVal, $postorder);
83-
$leftSize = $leftPostIdx + 1;
84-
85-
$leftPre = array_slice($preorder, 1, $leftSize);
86-
$leftPost = array_slice($postorder, 0, $leftSize);
87-
88-
$rightPre = array_slice($preorder, $leftSize + 1);
89-
$rightPost = array_slice($postorder, $leftSize, $n - $leftSize - 1);
90-
91-
$root->left = constructFromPrePost($leftPre, $leftPost);
92-
$root->right = constructFromPrePost($rightPre, $rightPost);
93-
94-
return $root;
72+
...
73+
...
74+
...
75+
/**
76+
* go to ./solution.php
77+
*/
9578
}
9679

9780
// Helper function to print tree in level-order

0 commit comments

Comments
 (0)