Python : Upper/Lower Approach [Preorder DFS] ✅
\nclass Codec:\n\n    def serialize(self, root: Optional[TreeNode]) -> str:\n        self.ans = []\n        \n        def dfs(node):\n            if not node: r
```\nclass Codec:\n\n    def serialize(self, root: Optional[TreeNode]) -> str:\n        self.ans = []\n        \n        def dfs(node):\n            if not node: return\n            self.ans.append(str(node.val))\n            dfs(node.left)\n            dfs(node.right)\n        \n        dfs(root)\n        return ",".join(self.ans)\n        \n\n    def deserialize(self, data: str) -> Optional[TreeNode]:\n        if not data: return None\n        ans = [int(d) for d in data.split(",")]\n        \n        \n        def dfs(ans, l, u):\n            if not ans: return None\n            if not l <= ans[0] <= u : return None\n            \n            node = ans.pop(0) #O(n)\n            root = TreeNode(node)\n            \n            root.left = dfs(ans, l, root.val)\n            root.right = dfs(ans, root.val, u)\n            \n            return root\n        return dfs(ans, -float(\'inf\'), float(\'inf\'))\n```\n\nExplaination : After 13 October 2022\nhttps://youtu.be/01f4F9HOb5k\n
['Depth-First Search', 'Python', 'Python3']