2 parents 97a25d1 + 561b3d9 commit 195b724Copy full SHA for 195b724
1 file changed
leetcode3/이진희/226. Invert Binary Tree.java
@@ -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
+
19
+ if (root == null) return null;
20
21
+ TreeNode tmp = root.left;
22
+ root.left = root.right;
23
+ root.right = tmp;
24
25
+ invertTree(root.left);
26
+ invertTree(root.right);
27
28
+ return root;
29
+ }
30
31
+}
0 commit comments