Skip to content

[jaekwang97] WEEK 04 Solutions - #2751

Merged
parkhojeong merged 3 commits into
DaleStudy:mainfrom
JAEKWANG97:week-04-solutions
Jul 19, 2026
Merged

[jaekwang97] WEEK 04 Solutions#2751
parkhojeong merged 3 commits into
DaleStudy:mainfrom
JAEKWANG97:week-04-solutions

Conversation

@JAEKWANG97

@JAEKWANG97 JAEKWANG97 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 코인 교환 문제에서 금액을 작은 부분 문제로 나누어 최적해를 구하는 DP 풀이입니다. 각 금액에 대해 가능한 동전들로 최소 개수를 업데이트하는 전형적인 동적계획 패턴입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(amount * len(coins))
Space O(amount)

피드백: 동전 종류를 모두 순회하며 각 합에 대해 최솟값을 갱신한다. dp 배열 크기는 amount+1 이므로 필요 공간은 선형이다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search
  • 설명: 회전된 정렬 배열에서 최소값을 이분탐색으로 찾는 패턴으로, 중간값과 양 끝값의 비교를 통해 탐색 구간을 절반으로 축소합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(log n)
Space O(1)

피드백: 왼쪽/오른쪽 포인터를 이용한 이진 검색으로 최솟값의 위치를 좁혀 간다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Binary Search
  • 설명: 트리의 깊이를 탐색하며 각 노드의 깊이를 추적하는 DFS 구현으로 깊이 우선 탐색 패턴에 해당합니다. 이 문제는 이진 트리의 최대 깊이를 재귀적으로 구합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(h)

피드백: 전역 max 변수를 사용해 현재 깊이를 추적하며 재귀적으로 자식 노드를 탐색한다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Merge sort related / Divide and Conquer
  • 설명: 두 정렬된 연결리스트를 순차 탐색하며 더 작은 값을 차례로 연결하는 방식으로, 두 포인터를 이용해 합치는 흐름이 핵심이다. 리스트를 순회하며 새로운 리스트를 만들어 결과를 구성한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n + m)
Space O(n + m)

피드백: 새로운 노드를 만들어 두 리스트를 병합한다. 최종 길이는 합의 길이이다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Backtracking
  • 설명: 단어를 한 칸씩 탐색하며 연결 경로를 재귀적으로 따라가고, 방문한 칸은 임시로 표시해 되돌려놓는 방식으로 모든 경로를 탐색합니다. 이는 DFS와 백트래킹 패턴의 전형적인 예입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n * m * 4^L)
Space O(n * m)

피드백: 모든 시작 위치에서 DFS를 수행하고, 방문 표식을 이용해 중복 방문을 방지한다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

@JAEKWANG97 JAEKWANG97 moved this from Solving to In Review in 리트코드 스터디 8기 Jul 18, 2026

@parkhojeong parkhojeong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다.

Comment on lines +5 to +18
int[] dp = new int[amount + 1];

Arrays.fill(dp, amount + 1);
dp[0] = 0;

for (int i = 1; i <= amount; i++) {
for (int coin : coins) {
if (i - coin >= 0) {
dp[i] = Math.min(dp[i], dp[i - coin] + 1);
}
}
}

return dp[amount] == amount + 1 ? -1 : dp[amount];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount + 1 이 매직넘버라 선언해서 사용하시면 좋을 거 같습니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

감사합니다. 상수 처리하면 가독성이 더 좋아질 것 같네요!

Comment on lines +6 to +9
while (left < right) {
int mid = left + (right - left) / 2;

if (nums[mid] > nums[right]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

탐색 중간에 답인 경우 리턴이 가능해서 최적화 해보시면 좋을 거 같습니다.

Comment on lines +2 to +23
private int max;

public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}

max = 0;
dfs(root, 1);

return max;
}

private void dfs(TreeNode node, int depth) {
if (node == null) {
return;
}

max = Math.max(max, depth);

dfs(node.left, depth + 1);
dfs(node.right, depth + 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전역변수 없이 dfs 리턴 값을 사용해보셔도 좋을 거 같습니다.

Comment on lines +7 to +27
if (list1.val <= list2.val) {
tail.next = new ListNode(list1.val);
list1 = list1.next;
} else {
tail.next = new ListNode(list2.val);
list2 = list2.next;
}

tail = tail.next;
}

while (list1 != null) {
tail.next = new ListNode(list1.val);
tail = tail.next;
list1 = list1.next;
}

while (list2 != null) {
tail.next = new ListNode(list2.val);
tail = tail.next;
list2 = list2.next;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListNode 를 새로 만들지 않고 기존 노드만을 이용해서 풀어보셔도 좋을 거 같습니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 돌려보니 runtime 50% 정도 나와서 최적화 좀 더 해보셔도 좋을 거 같습니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앞으로 풀이할 때 Beats도 같이 봐아겠네요. 백분위였군요👍

@JAEKWANG97 JAEKWANG97 moved this from In Review to Completed in 리트코드 스터디 8기 Jul 19, 2026
@parkhojeong
parkhojeong merged commit 6955953 into DaleStudy:main Jul 19, 2026
1 check passed
okyungjin pushed a commit to okyungjin/leetcode-study that referenced this pull request Jul 20, 2026
* Add week 04 solutions for merge, max depth, find min

* Add coin change solution

* Add word search solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

3 participants