mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-22 16:31:15 -04:00
Update bt_construct_inorder_preorder.py
This commit is contained in:
parent
e5efd5424a
commit
dd98393aa4
1 changed files with 2 additions and 3 deletions
|
@ -10,11 +10,10 @@ def build_tree(preorder, inorder) -> Optional[Node]:
|
|||
if left > right:
|
||||
return None
|
||||
|
||||
root = Node(preorder.pop(0))
|
||||
root = Node(preorder.pop(0)) # # this order change from postorder
|
||||
index_here = index_map[root.val]
|
||||
|
||||
# this order change from postorder
|
||||
root.left = helper(left, index_here - 1, index_map)
|
||||
root.left = helper(left, index_here - 1, index_map) # this order change from postorder
|
||||
root.right = helper(index_here + 1, right, index_map)
|
||||
|
||||
return root
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue