[dahyeong-yun] WEEK 11 Solutions - #2847
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
missing-number/dahyeong-yun.java
/**
* 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;
}
}- 패턴: Greedy, Dynamic Programming, Bit Manipulation, Hash Map / Hash Set, Divide and Conquer, Two Pointers, Sliding Window, Fast & Slow Pointers, BFS, DFS, Backtracking, Union Find, Trie, Heap / Priority Queue, Monotonic Stack, Binary Search, Dynamic Programming
- 설명: 해당 코드는 등차수열 합 공식으로 누락된 숫자를 찾는 문제 해결. 한 번의 순회로 합계를 구하고, 전체 합에서 실제 합을 빼 누락 수를 얻는 방식으로 O(n) 시간, O(1) 공간이다.
📊 시간/공간 복잡도 분석
| 유저 분석 | 실제 분석 | 결과 | |
|---|---|---|---|
| Time | O(n) | O(n) | ✅ |
| Space | O(1) | O(1) | ✅ |
피드백: 배열을 한 번 순회하면서 합을 구하고, 수열의 전체 합과 비교해 누락된 값을 얻는다.
개선 제안: 현재 구현이 적절해 보입니다.
Contributor
📊 dahyeong-yun 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
alphaorderly
reviewed
Sep 4, 2026
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
merge-intervals/dahyeong-yun.java
/**
* 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<int[]> 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][]);
}
}- 패턴: Greedy, Two Pointers, Sorting
- 설명: intervals를 시작 값 기준으로 정렬한 뒤, 현재 구간과 다음 구간의 겹침 여부를 순차적으로 확인하며 합치거나 새 구간을 시작하는 방식으로 문제를 해결하므로 Greedy 패턴과 Two Pointers의 연속 비교가 핵심이다. 또한 정렬이 선행되므로 Sorting도 함께 해당한다.
📊 시간/공간 복잡도 분석
| 유저 분석 | 실제 분석 | 결과 | |
|---|---|---|---|
| Time | O(n log n) | O(n log n) | ✅ |
| Space | O(n) | O(n) | ✅ |
피드백: 정렬으로 시작해 이후 순회에서 현재 구간과 다음 구간의 교집합 여부를 검사해 합치는 형태로, 전체 시간 복잡도는 O(n log n), 추가 공간은 리스트 저장 등으로 O(n)이다.
개선 제안: 현재 구현이 적절해 보입니다.
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
reorder-list/dahyeong-yun.java
/**
* TC : O(n)
* - 배열을 한 번 순회하면서 합을 구하기 때문에 O(n)
* SC : O(n)
* - ArrayList가 노드 전체의 길이 n만큼 할당되기 때문에 O(n)
*/
class Solution {
public void reorderList(ListNode head) {
List<ListNode> 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;
}
}- 패턴: Two Pointers, Greedy, Hash Map / Hash Set
- 설명: 리스트를 배열에 저장한 후 양 끝에서 가리키며 순서를 재배치하는 방식으로 두 포인터를 교차시키는 패턴이 드러납니다. 원소 재배치를 위해 양 끝 포인터를 이동시키고, 각 포인터에 따라 연결 고리를 업데이트합니다.
📊 시간/공간 복잡도 분석
| 유저 분석 | 실제 분석 | 결과 | |
|---|---|---|---|
| Time | O(n) | O(n) | ✅ |
| Space | O(n) | O(n) | ✅ |
피드백: 전체를 한 번 순회하며 노드를 배열에 저장하고 다시 양 끝에서 연결하기 때문에 시간 복잡도는 선형이고, 보조 배열로 O(n) 공간이 필요하다.
개선 제안: 필요 시 추가 공간을 줄이려면 중간에 리스트를 반으로 나눠 역순으로 연결하는 방식 등으로 O(1) 추가 공간 구현을 고려해볼 수 있습니다.
yuseok89
approved these changes
Sep 5, 2026
Contributor
There was a problem hiding this comment.
SC O(1) 로 풀리는 풀이도 있으니 참고하세요 ~
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!