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;
}
};
将二叉树拆成链表 - C++
最新推荐文章于 2021-08-13 02:34:26 发布