We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3425a8a commit 775b2d0Copy full SHA for 775b2d0
invert-binary-tree/hu6r1s.py
@@ -0,0 +1,14 @@
1
+# Definition for a binary tree node.
2
+# class TreeNode:
3
+# def __init__(self, val=0, left=None, right=None):
4
+# self.val = val
5
+# self.left = left
6
+# self.right = right
7
+class Solution:
8
+ def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
9
+ if not root:
10
+ return
11
+ root.left, root.right = root.right, root.left
12
+ self.invertTree(root.left)
13
+ self.invertTree(root.right)
14
+ return root
0 commit comments