Algorithm · ByteDance · Medium
You are given two integer arrays, preorder and inorder, which record the preorder and inorder traversals, respectively, of one binary tree. Reconstruct that tree and return its root node. Implement buildTree(preorder, inorder) -> TreeNode. Each TreeNode has an integer val and left and right child pointers. Example: Explanation: The preorder sequence identifies 8 as the root, while the inorder sequence places 2, 4, and 6 in its left subtree and 12 in its right subtree.…
Checking your access…