/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *
Posted 爱编程的小羊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * 相关的知识,希望对你有一定的参考价值。
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: TreeNode* reConstructBinaryTree(vector<int> pre,vector<int> vin) { if(pre.size()==0||vin.size()==0) return NULL; TreeNode* p=new TreeNode(pre[0]); int i; for(i=0;i<vin.size();i++) if(pre[0]==vin[i]) break; vector<int> left_pre,left_vin,right_pre,right_vin; for(int j=0;j<i;j++) {left_pre.push_back(pre[j+1]); left_vin.push_back(vin[j]);} for(int j=i+1;j<pre.size();j++) {right_pre.push_back(pre[j]); right_vin.push_back(vin[j]);} p->left=reConstructBinaryTree(left_pre,left_vin); p->right=reConstructBinaryTree(right_pre,right_vin); return p; } };
以上是关于/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * 的主要内容,如果未能解决你的问题,请参考以下文章
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *
kinaba 安装踩坑: FATAL Error: [elasticsearch.url]: definition for this key is missing 转
IAR for STM8 右键go to definition无法跳转,怎么解决
论文阅读《High-Definition Map Generation Technologies For Autonomous Driving: A Review》1
IAR 9+ 编译 TI CC2541 出现 Segment ISTACK (size: 0xc0 align: 0) is too long for segment definition.(示例代码
[Nagios] Error: Template 'timman' specified in contact definition could not be not