pre&in-order input
leetCode105 : given preorder and inorder traversal of a tree, construct the binary tree.
sol: each top node in Btree, has left-branch and right-branch, and each branch is a similar-structure subtree. so every time pop out the top node, and recursive the two subtrees, which return as the left kid and right kid of current top node.
the recursive stopped when the list is empty(in real case, this means the node has only either left or right kid); or stopped when only one element in the list(in real case, the node has both kids, so left or right subtree has only one element).
|
|
in each recursive step, I am using exteral containers, same stragey in scramble string. is there a one-swap way?
post/in-order input
|
|