Skip to content

Commit d9aaae6

Browse files
sean424DaleSeo
andauthored
Update invert-binary-tree/bhyun-kim.py
Co-authored-by: Dale Seo <[email protected]>
1 parent bbf9378 commit d9aaae6

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

invert-binary-tree/bhyun-kim.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,10 @@ def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
3131
has_right = hasattr(root, "right")
3232

3333
if has_left and has_right:
34-
root.left = self.invertTree(root.left)
35-
root.right = self.invertTree(root.right)
36-
root.left, root.right = root.right, root.left
34+
root.left, root.right = self.invertTree(root.right), self.invertTree(root.left)
3735
elif has_left:
38-
root.left = self.invertTree(root.left)
39-
root.left, root.right = None, root.left
36+
root.left, root.right = None, self.invertTree(root.left)
4037
elif has_right:
41-
root.right = self.invertTree(root.right)
42-
root.left, root.right = root.right, None
38+
root.left, root.right = self.invertTree(root.right), None
4339

4440
return root

0 commit comments

Comments
 (0)