Update bt_construct_inorder_postorder.py

This commit is contained in:
bt3gl 2023-08-08 19:55:27 -07:00 committed by GitHub
parent bbdd47ffd3
commit 14404c47c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,9 +7,10 @@ def build_tree(left, right, index_map, postorder):
if left > right:
return None
root = Node(postorder.pop()) # this order change from preorder
index_here = index_map[root.val]
node = postorder.pop() # this order change from preorder
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.left = build_tree(left, index_here - 1, index_map, postorder)