From f8399bbe2c2ed163f7e4b6cf0e1f15cb6f475772 Mon Sep 17 00:00:00 2001 From: danny Date: Thu, 3 Sep 2026 21:22:01 +0900 Subject: [PATCH 1/3] 0268-missing-number --- missing-number/dahyeong-yun.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 missing-number/dahyeong-yun.java diff --git a/missing-number/dahyeong-yun.java b/missing-number/dahyeong-yun.java new file mode 100644 index 0000000000..0056413e99 --- /dev/null +++ b/missing-number/dahyeong-yun.java @@ -0,0 +1,15 @@ +/** + * TC : O(n) + * - 배열을 한 번 순회하면서 합을 구하기 때문에 n + * SC : O(1) + * - 별도 유의미한 공간 할당이 없음 + */ +class Solution { + public int missingNumber(int[] nums) { + int n = nums.length; + int total = n * (n + 1) / 2; + int sum = 0; + for(int num : nums) sum+=num; + return total - sum; + } +} From afa9602807d99638c1dd1af1163cf3212a952670 Mon Sep 17 00:00:00 2001 From: danny Date: Fri, 4 Sep 2026 21:39:41 +0900 Subject: [PATCH 2/3] 0143-reorder-list --- reorder-list/dahyeong-yun.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 reorder-list/dahyeong-yun.java diff --git a/reorder-list/dahyeong-yun.java b/reorder-list/dahyeong-yun.java new file mode 100644 index 0000000000..d67627d820 --- /dev/null +++ b/reorder-list/dahyeong-yun.java @@ -0,0 +1,26 @@ +/** + * TC : O(n) + * - 배열을 한 번 순회하면서 합을 구하기 때문에 O(n) + * SC : O(n) + * - ArrayList가 노드 전체의 길이 n만큼 할당되기 때문에 O(n) + */ +class Solution { + public void reorderList(ListNode head) { + List nodes = new ArrayList<>(); + for (ListNode cur = head; cur != null; cur = cur.next) + nodes.add(cur); + + int i = 0; + int j = nodes.size() - 1; + + while (i < j) { + nodes.get(i).next = nodes.get(j); + i++; + if (i == j) break; + nodes.get(j).next = nodes.get(i); + j--; + } + + nodes.get(j).next = null; + } +} From 9902c66f80436df35c41788352d211cb87f0cbb8 Mon Sep 17 00:00:00 2001 From: danny Date: Sat, 5 Sep 2026 12:00:04 +0900 Subject: [PATCH 3/3] 0056-merge-intervals --- merge-intervals/dahyeong-yun.java | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 merge-intervals/dahyeong-yun.java diff --git a/merge-intervals/dahyeong-yun.java b/merge-intervals/dahyeong-yun.java new file mode 100644 index 0000000000..f7c8242e67 --- /dev/null +++ b/merge-intervals/dahyeong-yun.java @@ -0,0 +1,35 @@ +/** + * TC : O(n log n) + * - 처음에 Arrays.sort() 하는데 O(n log n) 소요. 이하 for loop는 O(n) + * SC : O(n) + * - intervals 배열의 크기 n 만큼 ArrayList 할당하므로 O(n) + */ +class Solution { + // 정확히 작업 정렬 하는 거랑 비슷한데 그걸 위상정렬이라 하던가. + // 각 0 번째 인덱스 값으로 정렬되어 있으면 + // 1번째 인덱스 값이 직전 interval[0] <= value <= interval[1] 인 경우에 합쳐진다. + // 겹치는 값이나 중복 값이 없다는 조건이 없다. 정렬도 보장되어 있지 않다. + // 하나씩 넣고 구간에 걸치는 경우에 합칠지 버릴지를 결정하면 될 듯 한데, 그걸 어떻게 n^2이 아닌 방식으로 하지 + public int[][] merge(int[][] intervals) { + List answer = new ArrayList<>(); + Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0])); + + int currentStart = intervals[0][0]; + int currentEnd = intervals[0][1]; + + for (int i = 1; i < intervals.length; i++) { + int[] pair = intervals[i]; + + if (currentEnd >= pair[0]) { + currentEnd = Math.max(currentEnd, pair[1]); + } else { + answer.add(new int[] { currentStart, currentEnd }); + currentStart = pair[0]; + currentEnd = pair[1]; + } + } + answer.add(new int[] { currentStart, currentEnd }); + + return answer.toArray(new int[0][]); + } +}