Python solution serializing as Preorder list
The remarkable difference from serialize/deserialize Binary Tree ( https://leetcode.com/problems/serialize-and-deserialize-binary-tree/ ) is, BST can be constru
The remarkable difference from serialize/deserialize Binary Tree ( https://leetcode.com/problems/serialize-and-deserialize-binary-tree/ ) is, **BST can be constructed just from its preorder array** while a general binary tree requires both [in-order and and pre-order](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/#/description ) or [in-order and post-order](https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/#/description).\n\nSo for serializing BST, just perform a pre-order traversal and stringify the result array.\nDeserialization can be also done in the same manner as:\nhttp://www.geeksforgeeks.org/construct-bst-from-given-preorder-traversal-set-2/\n\n```\nclass Codec:\n    def serialize(self, root):\n        if not root:\n            return "none"\n        cur = root\n        \n        res = ""\n        stack = []\n        while cur:\n            res += str(cur.val) + ","\n            \n            if cur.right:\n                stack.append(cur)\n            \n            if cur.left:\n                cur = cur.left\n            elif not stack:\n                break\n            else:\n                cur = stack.pop()\n                cur = cur.right\n        return res[:-1] # remove the last ","\n          \n    def deserialize(self, data):\n        if data == "none":\n            return None\n        vals = data.split(",")\n        root = TreeNode(int(vals[0]))\n        cur = root\n        \n        stack = []\n        for i in range(1, len(vals)):\n            val = int(vals[i])\n            \n            if val < cur.val:\n                cur.left = TreeNode(val)\n                stack.append(cur)\n                cur = cur.left\n            else:\n                while stack and cur.val < val:\n                    if stack[-1].val < val:\n                        cur = stack.pop()\n                    else:\n                        break\n                cur.right = TreeNode(val)\n                cur = cur.right\n        return root\n            \n```
['Python']