mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 20:26:07 -04:00
Update bt_construct_inorder_preorder.py
This commit is contained in:
parent
e5efd5424a
commit
dd98393aa4
@ -10,11 +10,10 @@ def build_tree(preorder, inorder) -> Optional[Node]:
|
|||||||
if left > right:
|
if left > right:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
root = Node(preorder.pop(0))
|
root = Node(preorder.pop(0)) # # this order change from postorder
|
||||||
index_here = index_map[root.val]
|
index_here = index_map[root.val]
|
||||||
|
|
||||||
# this order change from postorder
|
root.left = helper(left, index_here - 1, index_map) # this order change from postorder
|
||||||
root.left = helper(left, index_here - 1, index_map)
|
|
||||||
root.right = helper(index_here + 1, right, index_map)
|
root.right = helper(index_here + 1, right, index_map)
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
Loading…
x
Reference in New Issue
Block a user