Simple Python preorder
In serialize step we do a preorder traversal to get the string. For reconstructing the BST, l and r are the left and right boundaries of our current array. Sinc
In ```serialize``` step we do a preorder traversal to get the string. For reconstructing the BST, ```l``` and ```r``` are the left and right boundaries of our ```current``` array. Since it's preorder traversal, for root value ```A[l]```, once we find the first point ```A[mid] < A[l]```, we know all values from this point until the right boundary are for the right subtree, and points before that until left boundary are the left subtree.\n```\nclass Codec:\n\n    def serialize(self, root):\n        """Encodes a tree to a single string.\n        \n        :type root: TreeNode\n        :rtype: str\n        """\n        def preorder(node):\n            if node:\n                res.append(str(node.val))\n                preorder(node.left)\n                preorder(node.right)\n        res = []\n        preorder(root)\n        return " ".join(res)\n        \n\n    def deserialize(self, data):\n        """Decodes your encoded data to tree.\n        \n        :type data: str\n        :rtype: TreeNode\n        """\n        def build(l, r):\n            if l >= r: return None\n            root = TreeNode(A[l])\n            mid = l+1\n            while mid < r and A[mid] < root.val: mid += 1\n            root.left = build(l+1, mid)\n            root.right = build(mid, r)\n            return root\n            \n        A = map(int, data.split())\n        return build(0, len(A))\n```
[]