Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2973 from coopers/0226
Browse files Browse the repository at this point in the history
Update 0226-invert-binary-tree.py
  • Loading branch information
felivalencia3 committed Sep 4, 2023
2 parents c581ec1 + 586e0e5 commit 2eb4ff8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions python/0226-invert-binary-tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
# self.left = left
# self.right = right
class Solution:
def invertTree(self, root: TreeNode) -> TreeNode:
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
if not root:
return None

# swap the children
tmp = root.left
root.left = root.right
root.right = tmp

root.left, root.right = root.right, root.left

# make 2 recursive calls
self.invertTree(root.left)
self.invertTree(root.right)
return root

0 comments on commit 2eb4ff8

Please sign in to comment.