[C++] Clean Solution using Vector
Solution\n\nApproach\n1. \',\'(comma) divides the string into \'#\' and node values\n2. Try to separate them and form a string with no \',\' and only \'#\' and 
**Solution**\n\n**Approach**\n1. \',\'(comma) divides the string into \'#\' and node values\n2. Try to separate them and form a string with no \',\' and only \'#\' and integers(node values)\n3. Now, the approach is to convert every triplet <integer, #, #> to #\n4. The triplet mentioned above defines a leaf node and thus we can easily find the leaf nodes and replace them with a null(#) character.\n5. Atlast, we should end with a null(#) character. This helps us to know that the preorder serialization was perfect and thus return true. Otherwise, return false.\n\n**Code**\n```\nclass Solution {\npublic:\n    bool isValidSerialization(string preorder) {\n        string ans = "";\n        vector<string> v;\n        for(int i = 0; i < preorder.size(); i++){\n            if(preorder[i] == \',\'){\n                v.push_back(ans);\n                while(v.size() >= 3 and v[v.size() - 1] == "#" and v[v.size() - 2] == "#" and v[v.size() - 3] != "#"){\n                    v.erase(v.begin() + v.size() - 1);\n                    v.erase(v.begin() + v.size() - 1);\n                    v.erase(v.begin() + v.size() - 1);\n                    v.push_back("#");\n                }\n                ans = "";\n            }\n            else\n                ans += preorder[i];\n        }\n        if(!ans.empty()){\n            v.push_back(ans);\n            while(v.size() >= 3 and v[v.size() - 1] == "#" and v[v.size() - 2] == "#" and v[v.size() - 3] != "#"){\n                v.erase(v.begin() + v.size() - 1);\n                v.erase(v.begin() + v.size() - 1);\n                v.erase(v.begin() + v.size() - 1);\n                v.push_back("#");\n            }\n            ans = "";\n        }\n        if(v.size() == 1 and v[0] == "#")\n            return true;\n        else return false;\n    }\n};\n```\n\n**Feel free to share your ideas or any improvements as well**
['C', 'Binary Tree']