标签:实现 默认 public amp return 反序 nbsp 函数 先序
class Solution { public: vector<int> vec; void Ser(TreeNode *pNode) { if (!pNode) vec.push_back(0x12345); else { vec.push_back(pNode->val); Ser(pNode->left); Ser(pNode->right); } } TreeNode *Des(int *&p) { if (*p == 0x12345) { p++; return NULL; } TreeNode *res = new TreeNode(*p); p++; res->left = Des(p); res->right = Des(p); return res; } char *Serialize(TreeNode *root) { vec.clear(); Ser(root); int *res = new int[vec.size()]; for (int i = 0; i < vec.size(); i++) res[i] = vec[i]; return (char *)res; } TreeNode *Deserialize(char *str) { int *p = (int *)str; return Des(p); } };
标签:实现 默认 public amp return 反序 nbsp 函数 先序
原文地址:https://www.cnblogs.com/ruoh3kou/p/10251956.html