将二叉树拆成链表
来源:互联网 发布:淘宝客sina 编辑:程序博客网 时间:2024/06/08 08:42
1
\
1 2
/ \ \
2 5 => 3
/ \ \ \
3 4 6 4
\
5
\
6
class Solution {
public:
/**
* @param root: a TreeNode, the root of the binary tree
* @return: nothing
*/
// TreeNode *x;
// x=new TreeNode;
vector<int> a;
void look(TreeNode *root)
{
if(root==NULL)
return ;
a.push_back(root->val);
look(root->left);
look(root->right);
}
void flatten(TreeNode *root)
{
look(root);
TreeNode *x;
x=new TreeNode;
x=root;
for(int i=0;i<a.size();i++)
{
x->val=a[i];
x->left=NULL;
if(i!=a.size()-1)
x->right=new TreeNode;
x=x->right;
} // write your code here
// x->right=NULL;
}
};
- 将二叉树拆成链表
- LintCode: 将二叉树拆成链表
- 将二叉树拆成链表
- lintcode,将二叉树拆成链表
- LintCode 将二叉树拆成链表
- 将二叉树拆成链表-LintCode
- 将二叉树拆成链表
- 将二叉树拆成链表
- lintcode 将二叉树拆成链表
- 将二叉树拆成链表
- 将二叉树拆成链表
- lintcode将二叉树拆成链表
- 将二叉树拆成链表
- 将二叉树拆成链表
- 将二叉树拆成链表
- 将二叉树拆成链表
- 将二叉树拆成链表
- 将二叉树拆成链表
- 代理模式
- 三十七、SpringBoot配置属性之MQ
- 高阶篇:4.4)FTA故障树分析法-DFMEA的另外一张脸
- shell常用命令
- gradle这东西一知半解就好了
- 将二叉树拆成链表
- python正则匹配的知识总结
- Lucene教程--入门程序详解
- 对于Http的简单理解
- 聊一聊Srevlet ①
- 三十八、SpringBoot配置属性之Security
- LeetCode091 Decode Ways
- MySQL-联结表
- LeetCode092 Reverse Linked List II