克隆二叉树

来源:互联网 发布:linux vi编辑器c 编辑:程序博客网 时间:2024/05/17 15:57
class Solution {public:    /**     * @param root: The root of binary tree     * @return root of new tree     */     void look (TreeNode *root,TreeNode *&x)     {         if(root==NULL)         return;         x=new TreeNode;         x->val=root->val;                  look(root->left,x->left);         look(root->right,x->right);     }    TreeNode* cloneTree(TreeNode *root) {        TreeNode *x;        if(root==NULL)        return NULL;        x=new TreeNode;        look(root,x);        return x;        // Write your code here    }};

0 0
原创粉丝点击