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 aafdbbc commit df06aa0Copy full SHA for df06aa0
Invert Binary Tree
@@ -0,0 +1,31 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * public class TreeNode {
4
+ * int val;
5
+ * TreeNode left;
6
+ * TreeNode right;
7
+ * TreeNode() {}
8
+ * TreeNode(int val) { this.val = val; }
9
+ * TreeNode(int val, TreeNode left, TreeNode right) {
10
+ * this.val = val;
11
+ * this.left = left;
12
+ * this.right = right;
13
+ * }
14
15
+ */
16
+class Solution {
17
+ public TreeNode invertTree(TreeNode root) {
18
+ invert(root);
19
+ return root;
20
+ }
21
+ public void invert(TreeNode root){
22
+ if(root == null){
23
+ return ;
24
25
+ TreeNode temp = root.right;
26
+ root.right = root.left;
27
+ root.left = temp;
28
+ invert(root.left);
29
+ invert(root.right);
30
31
+}
0 commit comments