🌺26. Pre Order Traversal || 2 Solutions|| Short & Sweet Code || C++ Code Reference
Intuition\n1. By Using Any Traversal Technique PreOrder, PostOrder Or Level Order :\n    - Convert Tree To String \n    - Convert Back String To Tree \n# Approa
# Intuition\n1. By Using Any Traversal Technique PreOrder, PostOrder Or Level Order :\n    - Convert Tree To String \n    - Convert Back String To Tree \n# Approach\n1. I Traverse PreOrder Wise To Serialize The Tree Using `Preorder` Function  !\n2. In Deserialization I Parse The String & Store Node Values In Vector \n3. Then I Simply Convert It To Tree !! Using `Convert` Function !!\n\n> Solution 2 Is Similar , But Concised !\n\n# Code\n```cpp [Solution  1]\nclass Codec {\n    // Binary Tree Can Be Constructed From PreOrder Traversal If It Is Full Binary Tree\n    // So Serialize Such That If Child Are null You Include It In PreOrder Traversal \npublic:\n\n    // Serialize : \n\n    string S="";\n    string serialize(TreeNode* a) {\n        Preorder(a);\n        return S;\n    }\n    void Preorder(TreeNode* a){\n        if(!a) { S+="null,"; return; }\n\n        S=S+to_string(a->val)+",";\n        Preorder(a->left);\n        Preorder(a->right);\n    }\n\n    // Deserialize : \n\n    vector<string> V;\n    TreeNode* deserialize(string s) {\n        string t="";\n        for(auto & i : s)\n            if(i==\',\') { V.push_back(t); t=""; }\n            else t+=i;\n\n        int i=0;\n        return Convert(i);  \n    }\n    TreeNode* Convert(int& i){\n        if(i>=V.size()||V[i]=="null"){i++;return nullptr;}\n\n        TreeNode* a=new TreeNode(stoi(V[i++]));\n        a->left=Convert(i);\n        a->right=Convert(i);\n        return a;\n    }\n};\n```\n\n```cpp [Solution 2 ]\n\n    string serialize(TreeNode* a) {\n        if(!a) return "null,";\n        return to_string(a->val)+ "," +serialize(a->left)+serialize(a->right);        \n    }\n\n    int i=0;\n    TreeNode* deserialize(string s) {      \n        if(i>=s.size())return nullptr;\n\n        string t="";\n        while(s[i]!=\',\') t+=s[i++];\n        i++;\n\n        if(t=="null") return nullptr;\n        TreeNode* a=new TreeNode(stoi(t));\n        a->left=deserialize(s);\n        a->right=deserialize(s);\n        return a;\n    }\n};\n\n```\n\n---\n# *Guy\'s Upvote Pleasee !!* \n![up-arrow_68804.png](https://assets.leetcode.com/users/images/05f74320-5e1a-43a6-b5cd-6395092d56c8_1719302919.2666397.png)\n\n# ***(\u02E3\u203F\u02E3 \u035C)***\n\n\n
['String', 'Tree', 'Depth-First Search', 'Breadth-First Search', 'Design', 'Binary Search Tree', 'Recursion', 'C++']