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