copyTree2.PNG

copyTree2.PNG

# 代码

```/**
* Definition of TreeNode:
* public class TreeNode {
*     public int val;
*     public TreeNode left, right;
*     public TreeNode(int val) {
*         this.val = val;
*         this.left = this.right = null;
*     }
* }
*/
public class Solution {
/**
* @param root: The root of binary tree
* @return root of new tree
*/
public TreeNode cloneTree(TreeNode root) {
if(root == null)
return null;

TreeNode dst = new TreeNode(0);
dst.val = root.val;
dst.left = cloneTree(root.left);
dst.right = cloneTree(root.right);

return dst;
}
}```

381 篇文章35 人订阅

0 条评论

## 相关文章

8420

10930

7530

20850

8420

### Leetcode 103 Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' valu...

217100

14830

36780

### Leetcode 124 Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum. For this problem, a path is de...

22190

### Leetcode 173 Binary Search Tree Iterator

mplement an iterator over a binary search tree (BST). Your iterator will be ini...

21860