Serialize and rebuild a tree
Write two functions: serialize(root) that turns a binary tree into a string, and
deserialize(text) that turns that string back into an identical tree. Any format works
as long as the round trip reproduces the tree exactly, including None for an empty tree.
deserialize(serialize(tree)) -> a tree with the same shape and values
Pre-order with a marker for missing children is the usual choice: write val then the
left subtree then the right, and # for None. Rebuilding consumes the tokens in the
same order with recursion. Import TreeNode from checker.
def serialize(root):
...
def deserialize(text):
...