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 655a5ca commit 1869e07Copy full SHA for 1869e07
src/Concurrency/Problem_2_Invert_Binary_Tree.java
@@ -0,0 +1,29 @@
1
+package Concurrency;
2
+
3
+// Problem Statement: Invert Binary Tree (medium)
4
+// LeetCode Question: 226. Invert Binary Tree
5
6
+public class Problem_2_Invert_Binary_Tree {
7
8
+ class TreeNode {
9
+ int val;
10
+ TreeNode left;
11
+ TreeNode right;
12
+ public TreeNode(int val) {
13
+ this.val = val;
14
+ this.left = null;
15
+ this.right = null;
16
+ }
17
18
19
+ public static TreeNode invertTree(TreeNode root) {
20
+ if (root != null) {
21
+ invertTree(root.left);
22
+ invertTree(root.right);
23
+ TreeNode temp = root.right;
24
+ root.right = root.left;
25
+ root.left = temp;
26
27
+ return root;
28
29
+}
0 commit comments