One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as#.
_9_
/ \
3 2
/ \ / \
4 1 # 6
/ \ / \ / \
# # # # # #
Example 1: "9,3,4,#,#,1,#,#,2,#,6,#,#" Return true
Example 2: "1,#" Return false
不为空的节点 ,有2个出点, 1个入点, 为空的有0个出点, 1个入点。

网友评论