
3.从你头到尾打印链表
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) :
* val(x),next(NulL) {
* }
* };
*/
class Solution {
public:
vector
vector
vector
if(!head) return v2;
while(head){
v1.push_back(head->val);
head = head->next;
}
for(vector
v2.push_back(*iter);
}
return v2;
}
};
重建二叉树:
/**
* 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
if(pre.size()==0) return NulL;
TreeNode* t=new TreeNode(pre[0]);
int index = -1;
for(int i=0;i if(vin[i]==pre[0]) index = i; } vector vector vector vector t->left = reConstructBinaryTree(v1,v2); t->right = reConstructBinaryTree(v3,v4); return t; } }; 以上是内存溢出为你收集整理的剑指offer c++全部内容,希望文章能够帮你解决剑指offer c++所遇到的程序开发问题。 如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。 欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)