Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree.
preorder[preL] is always the root of the current subtreeleftSize = inMid - inL elements go to the left subtreebuild(left range) then build(right range)
preorder[0] is always the root.
Finding it in inorder splits the array into left and right subtrees.
The number of elements to the left
(leftSize = inMid − inL) tells us exactly which
portion of preorder belongs to the left subtree:
pre[preL+1 .. preL+leftSize].
Everything after belongs to the right. A HashMap pre-indexes
inorder values for O(1) lookup, giving overall
O(n) time.