Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 155d245

Browse files
committedOct 16, 2024·
implemented invert_binary_tree
1 parent 7d7e68c commit 155d245

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎data_structures/binary_tree/invert_binary_tree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, data: int) -> None:
2727

2828

2929
class MirrorBinaryTree:
30-
def mirror_binary_tree(self, root : TreeNode):
30+
def invert_binary_tree(self, root : TreeNode):
3131
"""
3232
Invert a binary tree and return the new root.
3333
@@ -36,13 +36,13 @@ def mirror_binary_tree(self, root : TreeNode):
3636
>>> tree = TreeNode(0)
3737
>>> tree.left = TreeNode(10)
3838
>>> tree.right = TreeNode(20)
39-
>>> result_tree = MirrorBinaryTree().mirror_binary_tree(tree)
39+
>>> result_tree = MirrorBinaryTree().invert_binary_tree(tree)
4040
>>> print_preorder(result_tree)
4141
0
4242
20
4343
10
4444
>>> tree2 = TreeNode(9)
45-
>>> result_tree2 = MirrorBinaryTree().mirror_binary_tree(tree2)
45+
>>> result_tree2 = MirrorBinaryTree().invert_binary_tree(tree2)
4646
>>> print_preorder(result_tree2)
4747
9
4848
"""
@@ -51,10 +51,10 @@ def mirror_binary_tree(self, root : TreeNode):
5151
return None
5252

5353
if root.left:
54-
self.mirror_binary_tree(root.left)
54+
self.invert_binary_tree(root.left)
5555

5656
if root.right:
57-
self.mirror_binary_tree(root.right)
57+
self.invert_binary_tree(root.right)
5858

5959
root.left, root.right = root.right, root.left
6060

0 commit comments

Comments
 (0)
Please sign in to comment.