Extra rep
Foundation Rep~3 min

A root over two finished subtrees

Write join(val, left, right): make a new node holding val, hang the already-built trees left and right under it (either can be None), and return the new root.

Example: join(1, build_tree([2, 4]), build_tree([3])) is the tree [1, 2, 3, 4].

Building toward LC 105 · Construct Binary Tree from Preorder and Inorder Traversal
Why this rep: block 1 of 5, make a node and attach its subtrees.

main.pylearnPython