forked from yingl/LintCodeInPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclone_binary_tree.py
More file actions
19 lines (17 loc) · 543 Bytes
/
clone_binary_tree.py
File metadata and controls
19 lines (17 loc) · 543 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# coding: utf-8
class Solution:
"""
@param {TreeNode} root: The root of binary tree
@return {TreeNode} root of new tree
"""
def cloneTree(self, root):
# Write your code here
new_root = None
if root:
new_root = TreeNode(root.val)
if root.left:
new_root.left = self.cloneTree(root.left)
if root.right:
new_root.right = self.cloneTree(root.right)
return new_root
# easy: http://lintcode.com/zh-cn/problem/clone-binary-tree/