Skip to content

Commit 2eb4ff8

Browse files
Merge pull request #2973 from coopers/0226
Update 0226-invert-binary-tree.py
2 parents c581ec1 + 586e0e5 commit 2eb4ff8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

python/0226-invert-binary-tree.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
# self.left = left
66
# self.right = right
77
class Solution:
8-
def invertTree(self, root: TreeNode) -> TreeNode:
8+
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
99
if not root:
1010
return None
11-
11+
1212
# swap the children
13-
tmp = root.left
14-
root.left = root.right
15-
root.right = tmp
16-
13+
root.left, root.right = root.right, root.left
14+
15+
# make 2 recursive calls
1716
self.invertTree(root.left)
1817
self.invertTree(root.right)
1918
return root

0 commit comments

Comments
 (0)