Skip to content

Commit 1869e07

Browse files
committed
Two-Hundred-Fifty-Nine Commit: Add Invert Binary Tree problem to Concurrency section
1 parent 655a5ca commit 1869e07

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)