Analysis:
Since this is not a complete binary search tree, we cannot use the index to dertermine the position of the child nodes.
use the preorder traversal to store the information
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | # Definition for a binary tree node. |