filmov
tv
Construct Binary Tree from Preorder and Inorder Traversal - Leetcode 105 - Python

Показать описание
Don't forget to check the following links:
Notes and theory:
Refined solution:
My blog:
Because each value is used to create exactly one node and each lookup in idx\_map takes constant time, the overall time complexity is linear in the number of nodes, n. We use O(n) extra space for idx\_map, and in the worst case (for a completely skewed tree) the recursion stack can also grow to depth n, making the space complexity O(n).
Notes and theory:
Refined solution:
My blog:
Because each value is used to create exactly one node and each lookup in idx\_map takes constant time, the overall time complexity is linear in the number of nodes, n. We use O(n) extra space for idx\_map, and in the worst case (for a completely skewed tree) the recursion stack can also grow to depth n, making the space complexity O(n).