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'

相关文章:

  • 2021-12-06
  • 2021-10-23
  • 2021-08-30
  • 2021-10-07
  • 2022-12-23
  • 2021-12-15
猜你喜欢
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2021-06-12
  • 2021-07-19
  • 2021-11-09
相关资源
相似解决方案