We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ea69035 commit 4ae3a68Copy full SHA for 4ae3a68
binary_tree_upside_down.py
@@ -0,0 +1,26 @@
1
+"""
2
+Definition of TreeNode:
3
+class TreeNode:
4
+ def __init__(self, val):
5
+ self.val = val
6
+ self.left, self.right = None, None
7
8
+
9
+class Solution:
10
+ """
11
+ @param root: the root of binary tree
12
+ @return: new root
13
14
+ def upsideDownBinaryTree(self, root):
15
+ # write your code here
16
+ # 递归版本,非递归待版本TODO。
17
+ if (root == None) or (root.left == None):
18
+ return root
19
+ _root = self.upsideDownBinaryTree(root.left)
20
+ root.left.left = root.right
21
+ root.left.right = root
22
+ root.left = None
23
+ root.right = None
24
+ return _root
25
26
+# medium: https://www.lintcode.com/problem/binary-tree-upside-down
0 commit comments