标签:序列 solution nbsp end dex struct public node 假设
class Solution { public: TreeNode *reConstructBinaryTree(vector<int> pre, vector<int> vin) { return helper(pre, 0, pre.size() - 1, vin, 0, vin.size() - 1); } TreeNode *helper(vector<int> pre, int pbeg, int pend, vector<int> vin, int vbeg, int vend) { if (pbeg > pend || vbeg > vend) return NULL; TreeNode *res = new TreeNode(pre[pbeg]); int index = 0; while (index < vend) { if (vin[index] == pre[pbeg]) break; index++; } cout << res->val << endl; res->left = helper(pre, pbeg + 1, pend + index - vbeg, vin, vbeg, index - 1); res->right = helper(pre, pbeg + 1 + index - vbeg, pend, vin, index + 1, vend); return res; } };
标签:序列 solution nbsp end dex struct public node 假设
原文地址:https://www.cnblogs.com/ruoh3kou/p/10043102.html