代码面试集锦 2 - Google
程序员文章站
2023-12-24 16:48:39
Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string ......
given the root to a binary tree, implement serialize(root), which serializes the tree into a string, and deserialize(s), which deserializes the string back into the tree.
for example, given the following node class
class node: def __init__(self, val, left=none, right=none): self.val = val self.left = left self.right = right
the following test should pass:
node = node('root', node('left', node('left.left')), node('right')) assert deserialize(serialize(node)).left.left.val == 'left.left'