From ae0afda79ea65acbd149a701773c93086d7fc48e Mon Sep 17 00:00:00 2001 From: juhui Date: Thu, 7 May 2026 22:44:24 +0900 Subject: [PATCH 1/3] WEEK 10 Solutions --- invert-binary-tree/juhuj-jeong.java | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 invert-binary-tree/juhuj-jeong.java diff --git a/invert-binary-tree/juhuj-jeong.java b/invert-binary-tree/juhuj-jeong.java new file mode 100644 index 0000000000..1ebb6c6fea --- /dev/null +++ b/invert-binary-tree/juhuj-jeong.java @@ -0,0 +1,60 @@ +/* +이전 풀이 + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) + */ +public class Solution { + public TreeNode invertTree(TreeNode root) { + if (root == null) { + return null; + } + + Queue queue = new LinkedList<>(); + queue.offer(root); + + while (!queue.isEmpty()) { + TreeNode cur = queue.poll(); + + TreeNode temp = cur.left; + cur.left = cur.right; + cur.right = temp; + + if (cur.left != null) { + queue.offer(cur.left); + } + + if (cur.right != null) { + queue.offer(cur.right); + } + } + + return root; + } +} + +/** + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) + * DFS 풀이 + */ +class Solution { + public TreeNode invertTree(TreeNode root) { + if (root == null) return null; + + Deque stack = new ArrayDeque<>(); + stack.push(root); + + while(!stack.isEmpty()) { + TreeNode cur = stack.pop(); + + TreeNode temp = cur.left; + cur.left = cur.right; + cur.right = temp; + + if (cur.left != null) stack.push(cur.left); + + if (cur.right != null) stack.push(cur.right); + } + return root; + } +} From 186e0bba33598ee67373e49e1d4df2fa91533f72 Mon Sep 17 00:00:00 2001 From: juhui Date: Thu, 7 May 2026 22:51:11 +0900 Subject: [PATCH 2/3] fix: WEEK 10 Solutions --- invert-binary-tree/juhui-jeong.java | 32 ++++++++++++++- invert-binary-tree/juhuj-jeong.java | 60 ----------------------------- 2 files changed, 30 insertions(+), 62 deletions(-) delete mode 100644 invert-binary-tree/juhuj-jeong.java diff --git a/invert-binary-tree/juhui-jeong.java b/invert-binary-tree/juhui-jeong.java index d03d60a5f1..1ebb6c6fea 100644 --- a/invert-binary-tree/juhui-jeong.java +++ b/invert-binary-tree/juhui-jeong.java @@ -1,6 +1,7 @@ /* - * 시간 복잡도: O(1) - * 공간 복잡도: O(1) +이전 풀이 + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) */ public class Solution { public TreeNode invertTree(TreeNode root) { @@ -30,3 +31,30 @@ public TreeNode invertTree(TreeNode root) { return root; } } + +/** + * 시간 복잡도: O(n) + * 공간 복잡도: O(n) + * DFS 풀이 + */ +class Solution { + public TreeNode invertTree(TreeNode root) { + if (root == null) return null; + + Deque stack = new ArrayDeque<>(); + stack.push(root); + + while(!stack.isEmpty()) { + TreeNode cur = stack.pop(); + + TreeNode temp = cur.left; + cur.left = cur.right; + cur.right = temp; + + if (cur.left != null) stack.push(cur.left); + + if (cur.right != null) stack.push(cur.right); + } + return root; + } +} diff --git a/invert-binary-tree/juhuj-jeong.java b/invert-binary-tree/juhuj-jeong.java deleted file mode 100644 index 1ebb6c6fea..0000000000 --- a/invert-binary-tree/juhuj-jeong.java +++ /dev/null @@ -1,60 +0,0 @@ -/* -이전 풀이 - * 시간 복잡도: O(n) - * 공간 복잡도: O(n) - */ -public class Solution { - public TreeNode invertTree(TreeNode root) { - if (root == null) { - return null; - } - - Queue queue = new LinkedList<>(); - queue.offer(root); - - while (!queue.isEmpty()) { - TreeNode cur = queue.poll(); - - TreeNode temp = cur.left; - cur.left = cur.right; - cur.right = temp; - - if (cur.left != null) { - queue.offer(cur.left); - } - - if (cur.right != null) { - queue.offer(cur.right); - } - } - - return root; - } -} - -/** - * 시간 복잡도: O(n) - * 공간 복잡도: O(n) - * DFS 풀이 - */ -class Solution { - public TreeNode invertTree(TreeNode root) { - if (root == null) return null; - - Deque stack = new ArrayDeque<>(); - stack.push(root); - - while(!stack.isEmpty()) { - TreeNode cur = stack.pop(); - - TreeNode temp = cur.left; - cur.left = cur.right; - cur.right = temp; - - if (cur.left != null) stack.push(cur.left); - - if (cur.right != null) stack.push(cur.right); - } - return root; - } -} From f2868efa49390477bfef8ace37b14c2abad19082 Mon Sep 17 00:00:00 2001 From: juhui Date: Fri, 8 May 2026 22:30:51 +0900 Subject: [PATCH 3/3] add: WEEK 10 Solutions --- .../juhui-jeong.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 search-in-rotated-sorted-array/juhui-jeong.java diff --git a/search-in-rotated-sorted-array/juhui-jeong.java b/search-in-rotated-sorted-array/juhui-jeong.java new file mode 100644 index 0000000000..89bec9ca9a --- /dev/null +++ b/search-in-rotated-sorted-array/juhui-jeong.java @@ -0,0 +1,34 @@ +/** + * 시간 복잡도: O(log n) + * 공간 복잡도: O(1) + */ +class Solution { + public int search(int[] nums, int target) { + int low = 0; + int high = nums.length - 1; + + while (low <= high) { + int mid = (low + high) / 2; + + if (nums[mid] == target) { + return mid; + } + // 왼쪽 구간이 정렬된 경우 + if (nums[low] <= nums[mid]) { + if (nums[low] <= target && target < nums[mid]) { + high = mid - 1; + } else { + low = mid + 1; + } + // 오른쪽 구간이 정렬된 경우 + } else { + if (nums[mid] < target && target <= nums[high]) { + low = mid + 1; + } else { + high = mid - 1; + } + } + } + return -1; + } +}