C++ || Serialize & Deserialize || Easy approach
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity:O(n)\n\n# Code\n\n/**\n * Definition for a binary tree node.
Here is my c++ code for this problem.\n\n# Complexity\n- Time complexity:$$O(n)$$\n\n- Space complexity:$$O(n)$$\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Codec {\npublic:\n\n    // Encodes a tree to a single string.\n    string serialize(TreeNode* root) {\n        string s="";\n        if(!root){\n            return s;\n        }\n        queue<TreeNode*>q;\n        q.push(root);\n        while(!q.empty()){\n            TreeNode* node=q.front();\n            q.pop();\n            if(!node){\n                s+="#,";\n            }\n            else{\n                s+=to_string(node->val)+\',\';\n                q.push(node->left);\n                q.push(node->right);\n            }\n        }\n        return s;\n    }\n\n    // Decodes your encoded data to tree.\n    TreeNode* deserialize(string data) {\n        if(data.empty()){return NULL;}\n        string s="";\n        stringstream x(data);\n        getline(x, s, \',\');\n        TreeNode* root=new TreeNode(stoi(s));\n        queue<TreeNode*>q;\n        q.push(root);\n        while(!q.empty()){\n            TreeNode* node=q.front();\n            q.pop();\n            getline(x, s, \',\');\n            if(s=="#"){\n                node->left=NULL;\n            }\n            else{\n                TreeNode* lft=new TreeNode(stoi(s));\n                node->left=lft;\n                q.push(lft);\n            }\n            getline(x, s, \',\');\n            if(s=="#"){\n                node->right=NULL;\n            }\n            else{\n                TreeNode* rgt=new TreeNode(stoi(s));\n                node->right=rgt;\n                q.push(rgt);\n            }\n        }\n        return root;\n    }\n};\n\n// Your Codec object will be instantiated and called as such:\n// Codec* ser = new Codec();\n// Codec* deser = new Codec();\n// string tree = ser->serialize(root);\n// TreeNode* ans = deser->deserialize(tree);\n// return ans;\n```
['String', 'Binary Search Tree', 'Binary Tree', 'C++']