How to rebuild the python binary tree, find out the maximum value of the gift, and calculate 1 binary 2 +. + n
How to rebuild the python binary tree, find out the maximum value of the gift, and calculate 1 binary 2 +. + n, aiming at this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Enter the results of preorder traversal and mid-order traversal of a binary tree, please rebuild the binary tree. Assume that the results of both the preorder traversal and the intermediate traversal of the input do not contain duplicate numbers.
For example, give the
Preorder traversal preorder = [3pm 9pm 20je 15rem 7]
Traversing in the middle order inorder = [9 ~ 1 ~ 3 ~ 15 ~ 20 ~ 7]
Return the following binary tree:
three
/\
9 20
/\
15 7
Restrictions:
0