--------------------------
水题
AC代码:
/** * 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 copycat=new TreeNode(root.val); copycat.left=cloneTree(root.left); copycat.right=cloneTree(root.right); return copycat; } }
题目来源: http://www.lintcode.com/zh-cn/problem/clone-binary-tree/#