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 3ac0528 commit 720398aCopy full SHA for 720398a
invert-binary-tree/TonyKim9401.java
@@ -0,0 +1,16 @@
1
+// TC: O(n)
2
+// -> visit all nodes to invert
3
+// SC: O(n)
4
+// -> create all nodes again to exchange
5
+class Solution {
6
+ public TreeNode invertTree(TreeNode root) {
7
+ if (root == null) return null;
8
+ invertTree(root.left);
9
+ invertTree(root.right);
10
+ TreeNode left = root.left;
11
+ TreeNode right = root.right;
12
+ root.left = right;
13
+ root.right = left;
14
+ return root;
15
+ }
16
+}
0 commit comments