欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

代码面试集锦 2 - Google

程序员文章站 2023-09-01 08:07:41
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'