class Solution:
def serialize(self, root):
if not root:
return ['#']
return [str(root.val)] + self.serialize(root.left) + self.serialize(root.right)
def deserialize(self, data):
ch = data.pop(0)
if ch == '#':
return None
else:
root = TreeNode(int(ch))
root.left = self.deserialize(data)
root.right = self.deserialize(data)
return root
我谢谢你嘞