Design two functions to serialize and deserialize a binary tree.
Assume the tree nodes are:
val
is an integer (may be negative)
left
/
right
pointers may be null
deserialize(serialize(root))
must produce a tree structurally identical to
root
with the same node values.
If the tree is:
1
as root
2
3
with children
4
and
5
Your serialized output could look like (format is up to you):
"1,2,#,#,3,4,#,#,5,#,#"
where # indicates null.