码迷,mamicode.com
首页 > 其他好文 > 详细

代码面试集锦 2 - Google

时间:2019-02-11 10:29:57      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:ack   str   int   roo   pass   amp   sel   binary   one   

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'

代码面试集锦 2 - Google

标签:ack   str   int   roo   pass   amp   sel   binary   one   

原文地址:https://www.cnblogs.com/Wonner/p/10360788.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!