Preorder serialize and recursive deserialize C++ 26ms
```\nclass Codec {\npublic:\n    //Encodes a tree to a single string.\n    void serialize(TreeNode root, vector &val)\n    {\n        if(root == NULL) return;\n
```\nclass Codec {\npublic:\n    //Encodes a tree to a single string.\n    void serialize(TreeNode* root, vector<int> &val)\n    {\n        if(root == NULL) return;\n        val.push_back(root->val);\n        serialize(root->left, val);\n        serialize(root->right, val);\n    }\n\n    string serialize(TreeNode* root) {\n        vector<int> val;\n        serialize(root, val);\n        char *p = (char*)val.data();\n        string str(p, val.size() * sizeof(int));\n        return str;\n    }\n    \n    // deserialize val[l .. r]\n    TreeNode* deserializeSubtree(int *val, int l, int r)\n    {\n        if(l > r) return NULL;\n        TreeNode *subRoot = new TreeNode(val[l]);\n        int i = l+1;\n        while(i <= r && val[i] < val[l]) ++i; \n        subRoot->left = deserializeSubtree(val, l+1, i-1);\n        subRoot->right = deserializeSubtree(val, i, r);\n        return subRoot;\n    }\n\n    // Decodes your encoded data to tree.\n    TreeNode* deserialize(string data) {\n        //preorder traversed string\n        int n = data.size() / sizeof(int);\n        TreeNode *root = deserializeSubtree((int*)data.data(), 0, n-1);\n        return root;\n    }\n    \n};
[]