105 Construct Binary Tree from Preorder and Inorder Traversal
105. Construct Binary Tree from Preorder and Inorder Traversal
1. Question
Given preorder and inorder traversal of a tree, construct the binary tree.
2. Implementation
(1) Recursion
(2) Iteration
3. Time & Space Complexity
Recursion: 时间复杂度O(n^2), 当树是skewed的时候,平均时间是O(nlogn), 空间复杂度O(n),因为用了map
Previous545 Boundary of Binary TreeNext106 Construct Binary Tree from Inorder and Postorder Traversal
Last updated
Was this helpful?