Python [recursion]
Serialize the pre-order traversal into a string. Reconstruct from this representation. Both functions can be implemented by recursion.\n\n\nclass Codec:\n    de
Serialize the pre-order traversal into a string. Reconstruct from this representation. Both functions can be implemented by recursion.\n\n```\nclass Codec:\n    def serialize(self, root: TreeNode) -> str:\n        if not root:\n            return \'\'\n        s1 = self.serialize(root.left)\n        s2 = self.serialize(root.right)\n        ret = str(root.val)\n        if s1: ret += \' \' + s1\n        if s2: ret += \' \' + s2\n        return ret\n\n    def deserialize(self, data: str) -> TreeNode:\n        if not data:\n            return []\n        def recur(arr):\n            this = TreeNode(arr[0])\n            left = [e for e in arr[1:] if e<arr[0]]\n            right = [e for e in arr[1:] if e>arr[0]]\n            if left: this.left = recur(left)\n            if right: this.right = recur(right)\n            return this\n        arr = data.strip().split(\' \')\n        arr = [int(e) for e in arr]\n        return recur(arr)\n```
[]