'Encodes a tree to a single string.
:type root: TreeNode
:rtype: str'

def serialize(self, root):

    def serializeHelper(node, vals):
        if node:
            vals.append(node.val)
            serializeHelper(node.left, vals)
            serializeHelper(node.right, vals)
    vals = []
    serializeHelper(root, vals)
    return '    '.join(map(str, vals))
