We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3c1f164 commit 4530cc3Copy full SHA for 4530cc3
clone_binary_tree.py
@@ -0,0 +1,17 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class Solution:
4
+ """
5
+ @param {TreeNode} root: The root of binary tree
6
+ @return {TreeNode} root of new tree
7
8
+ def cloneTree(self, root):
9
+ # Write your code here
10
+ new_root = None
11
+ if root:
12
+ new_root = TreeNode(root.val)
13
+ if root.left:
14
+ new_root.left = self.cloneTree(root.left)
15
+ if root.right:
16
+ new_root.right = self.cloneTree(root.right)
17
+ return new_root
0 commit comments