# LintCode:克隆二叉树

LintCode:克隆二叉树

"""
Definition of TreeNode:
class TreeNode:
def __init__(self, val):
this.val = val
this.left, this.right = None, None
"""
class Solution:
"""
@param {TreeNode} root: The root of binary tree
@return {TreeNode} root of new tree
"""
def cloneTree(self, root):
if not root:
return root

my_root = TreeNode(root.val)
self.pre_order_clone(my_root, root)
return my_root

def pre_order_clone(self, my_root, root):
if not root:
return
if root.left:
my_root.left = TreeNode(root.left.val)
self.pre_order_clone(my_root.left, root.left)
if root.right:
my_root.right = TreeNode(root.right.val)
self.pre_order_clone(my_root.right, root.right)


#### lintcode | 克隆二叉树

2017-02-06 10:37:01

#### lintcode：克隆二叉树

2017-08-29 18:54:58

#### 克隆二叉树-LintCode

2017-04-11 16:27:45

#### lintcode - 克隆二叉树

2016-09-05 08:46:31

#### lintcode,克隆二叉树

2016-12-17 17:46:59

#### Lintcode 克隆二叉树

2017-04-13 16:57:44

#### lintcode 375 克隆二叉树

2017-04-23 20:24:24

#### LintCode 克隆二叉树

2017-04-10 22:11:50

#### lintcode——克隆二叉树

2017-04-09 00:04:19

#### [LintCode]375.克隆二叉树

2017-08-17 22:17:45