← 返回 databricks 的题目列表Reconstruct a Binary Tree from Inorder Traversal (Follow-up)
类型:online_judge
Follow-up: Reconstruct a Binary Tree from Inorder Traversal
You are given the inorder traversal of a binary tree and asked to reconstruct the tree.
Notes
With only an inorder sequence, the original binary tree is not uniquely determined in general.
Discussion points
Explain why inorder alone is insufficient to uniquely reconstruct a binary tree.
Provide additional information that would make reconstruction possible (e.g., preorder or postorder).
Given such additional information (e.g., inorder + preorder), describe/implement the reconstruction algorithm and analyze its complexity.
Example
Input
preorder: [3,9,20,15,7]
inorder: [9,3,15,20,7]
Output
(reconstructed tree root=3)