将二叉树拆成链表

来源:互联网 发布:php oa 工作流引擎 编辑:程序博客网 时间:2024/06/16 06:27
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;    }};

0 0
原创粉丝点击