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 2e53834 commit b5ce480Copy full SHA for b5ce480
invert-binary-tree/Tessa1217.java
@@ -0,0 +1,36 @@
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
17
+ * 이진 트리의 root가 주어질 때 이진 트리를 뒤바꾼 후 root를 반환하세요.
18
19
+class Solution {
20
+ public TreeNode invertTree(TreeNode root) {
21
+
22
+ if (root == null) {
23
+ return root;
24
+ }
25
26
+ TreeNode current = root;
27
28
+ // 좌우 변경
29
+ TreeNode temp = current.left;
30
+ current.left = invertTree(current.right);
31
+ current.right = invertTree(temp);
32
33
34
35
+}
36
0 commit comments