File tree 1 file changed +5
-5
lines changed
data_structures/binary_tree
1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def __init__(self, data: int) -> None:
27
27
28
28
29
29
class MirrorBinaryTree :
30
- def mirror_binary_tree (self , root : TreeNode ):
30
+ def invert_binary_tree (self , root : TreeNode ):
31
31
"""
32
32
Invert a binary tree and return the new root.
33
33
@@ -36,13 +36,13 @@ def mirror_binary_tree(self, root : TreeNode):
36
36
>>> tree = TreeNode(0)
37
37
>>> tree.left = TreeNode(10)
38
38
>>> tree.right = TreeNode(20)
39
- >>> result_tree = MirrorBinaryTree().mirror_binary_tree (tree)
39
+ >>> result_tree = MirrorBinaryTree().invert_binary_tree (tree)
40
40
>>> print_preorder(result_tree)
41
41
0
42
42
20
43
43
10
44
44
>>> tree2 = TreeNode(9)
45
- >>> result_tree2 = MirrorBinaryTree().mirror_binary_tree (tree2)
45
+ >>> result_tree2 = MirrorBinaryTree().invert_binary_tree (tree2)
46
46
>>> print_preorder(result_tree2)
47
47
9
48
48
"""
@@ -51,10 +51,10 @@ def mirror_binary_tree(self, root : TreeNode):
51
51
return None
52
52
53
53
if root .left :
54
- self .mirror_binary_tree (root .left )
54
+ self .invert_binary_tree (root .left )
55
55
56
56
if root .right :
57
- self .mirror_binary_tree (root .right )
57
+ self .invert_binary_tree (root .right )
58
58
59
59
root .left , root .right = root .right , root .left
60
60
You can’t perform that action at this time.
0 commit comments