Skip to content

[dahyeong-yun] WEEK 04 Solutions - #2740

Merged
dahyeong-yun merged 6 commits into
DaleStudy:mainfrom
dahyeong-yun:main
Jul 18, 2026
Merged

[dahyeong-yun] WEEK 04 Solutions#2740
dahyeong-yun merged 6 commits into
DaleStudy:mainfrom
dahyeong-yun:main

Conversation

@dahyeong-yun

@dahyeong-yun dahyeong-yun commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

📊 dahyeong-yun 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
coin-change Medium ✅ 의도한 유형
find-minimum-in-rotated-sorted-array Medium ✅ 의도한 유형
maximum-depth-of-binary-tree Easy ✅ 의도한 유형
merge-two-sorted-lists Easy ✅ 의도한 유형
word-search Medium ✅ 의도한 유형

누적 학습 요약

  • 풀이한 문제: 15 / 75개
  • 이번 주 유형 일치율: 100% (5문제 중 5문제 일치)

문제 풀이 현황

카테고리 진행도 완료
Array ■■■■□□□ 5 / 10 (Medium 3, Easy 2)
Dynamic Programming ■■■□□□□ 4 / 11 (Easy 1, Medium 3)
Heap ■■□□□□□ 1 / 3 (Medium 1)
Binary ■□□□□□□ 1 / 5 (Easy 1)
String ■□□□□□□ 2 / 10 (Easy 2)
Graph ■□□□□□□ 1 / 8 (Medium 1)
Tree ■□□□□□□ 1 / 14 (Medium 1)
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함
Linked List □□□□□□□ 0 / 6 ← 아직 시작 안 함
Matrix □□□□□□□ 0 / 4 ← 아직 시작 안 함

🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다.

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 503 46 549 $0.000044
2 3,043 196 3,239 $0.000231
3 3,043 240 3,283 $0.000248
합계 6,589 482 7,071 $0.000522

@dolphinflow86
dolphinflow86 self-requested a review July 13, 2026 09:36
*/
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

ListNode merged = new 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.

@dahyeong-yun 보통 dummy로 많이 쓰는데 merged도 실제로 머지된 노드를 나타내는거라 괜찮아 보이네요!

Comment on lines +30 to +34
if(list1 != null) {
cursor.next = list1;
} else {
cursor.next = list2;
}

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.

@dahyeong-yun 3항 연산자로 쓰는것도 깔끔해 보입니다. (취향 차이이긴 하지만)

* - 이 경우 시간 복잡도는 두 노드의 길이의 합만큼 반복하게 되어 각 길이를 n, m 이라 했을 때 n+m이 됨
* - 별도의 유의미한 공간 할당을 하지 않으므로 O(1)의 공간복잡도를 가짐.
*/
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {

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.

@dahyeong-yun 깔끔하게 풀어주셔서 더 코멘트 달 부분이 없네요. 저도 거의 같은 방식으로 풀었는데 재귀를 활용한 방법도 있더라고요? 문제는 이게 공간복잡도가 더 높아져서 구현해보지는 않았습니다 ㅎㅎ 뭐라도 말씀드려야 할 것 같아서 주저리 써보았습니다.

@dahyeong-yun dahyeong-yun moved this from Solving to In Review in 리트코드 스터디 8기 Jul 17, 2026

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, Greedy
  • 설명: 금액별 최소 코인 수를 구하는 Q로, 각 코인으로 상태를 업데이트하는 DP(2차원 아님) 패턴으로 풀이합니다. 코인 목록을 순회하며 금액 상태를 최소로 갱신하는 방식이 DP의 전형적인 예이며, 부분 문제 해를 합쳐 최종 해를 구합니다. 또한 문제의 특성상 최적해를 구하는 탐욕적 요소가 보일 수 있지만 실제 풀이에서 DP로 정확한 해를 계산합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N * amount) O(n * amount)
Space O(amount) O(amount)

피드백: 배낭형 DP로 각 금액별 최소 동전 수를 갱신하는 전형적인 풀이이며, 외부 루프가 코인 수, 내부 루프가 금액을 순회합니다.

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

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) O(log n)
Space O(1) 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search, Depth-First Search, Divide and Conquer
  • 설명: 루트부터 자식 노드를 재귀적으로 탐색하며 깊이를 1씩 증가시키고, 좌우 자식의 최대 깊이를 합쳐 최댓값을 구하는 전형적인 DFS/재귀를 활용한 Divide and Conquer 패턴으로 최대 깊이를 구합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n) O(n)
Space O(h) O(h)

피드백: 모든 노드를 방문하며 트리의 깊이에 비례하는 호출 스택을 사용합니다.

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

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 / Two Pointer Technique
  • 설명: 두 정렬 리스트를 한 순서대로 합치는 과정에서 두 포인터(list1, list2)를 이동시키며 값을 비교해 새로운 연결 리스트를 만들어 간다. 모든 원소를 한 번씩 방문하므로 시간은 O(n+m), 추가 공간은 상수입니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n+m) O(n + m)
Space O(1) O(1)

피드백: 두 리스트를 순차 비교하여 새로운 노드를 생성하지 않고 노드를 연결합니다.

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

Comment thread word-search/dahyeong-yun.java
Comment on lines +52 to +53
// 현재 좌표 방문 처리
visited[curRow][curCol] = true;

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.

@dahyeong-yun 저도 처음에 이렇게 visited 썼다가, 나중에 보니 해당 보드에 문자를 #와 같은걸로 마킹하고 다시 함수 끝에서 돌려놓으면 굳이 visited가 필요없더라고요! 요 방법도 적용해보셔도 좋을 것 같아요.

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.

그거 엄청 좋은 방식이네요!
visited로 임의 공간 사용 안해도 되니까 좋네요

@@ -0,0 +1,81 @@
/**
* [풀이 개요]
* - 시간복잡도 : O(N * M * 3^L)

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.

@dahyeong-yun 저는 이 문제 시간복잡도 분석에 시간이 좀 걸렸었는데, 혹시 어떻게 분석을 접근하셨는지 한번 풀어서 설명해주실 수 있나요?

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.

저도 쉽지 않았던 것 같아요. 정리된 생각으로 말씀드리면,

  • find를 하기 전에 바깥 쪽에 이중 루프가 있으므로 일단 n * m(즉, 가로 길이 * 세로 길이) 만큼은 순회를 한다고 봤고요.
  • find를 하면 각 글자에서 3방향으로 다시 뻗어 나가니까, 재귀가 호출 될 때마다 3씩 곱한만큼 콜스택이 쌓일거라 3^x 형태가 된다고 생각했어요. 이 때 x가 무엇일까 생각하면, 재귀는 단어의 길이까지 찾고 멈추니까 단어의 길이가 되겠네요.

(분석이 맞는지는 잘 모르겠네요)

methods[j] = Math.min(methods[j], methods[j - coin] + 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.

이 부분 j 시작점을 coin으로 바꾸시면 훨씬 보기 좋을것 같아요! 반복 횟수도 줄어들구요

for(int j=coin; j <= amount; j++) {
    methods[j] = Math.min(methods[j], methods[j - coin] + 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.

그렇네요. 어차피 그 부분을 체크를 안해도 되니까 분기를 만들 필요가 없네요 👍🏼

@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 +20 to +27
for(int i=0; i<coins.length; i++) {
int coin = coins[i];
for(int j=1; j <= amount; j++) {
if(j >= coin) {
methods[j] = Math.min(methods[j], methods[j - coin] + 1);
}
}
}

@parkhojeong parkhojeong Jul 17, 2026

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.

i, j, coin, amount 등이 섞여 있어 이해하는데 약간 어려웠던 거 같습니다.

1부터 amount 까지 가는 루프만 인덱스를 필요로 하니 이 떄만 i를 사용해서 루프를 돌리고 코인은 변수 값을 바로 쓰는 형태로 써보셔도 좋을 거 같습니다. 포문 순서는 바꾸셔도 될 거 같은데 점화식 형태로 업데이트하니 바깥 포문은 1~amount까지 돌리는게 생각의 흐름과 맞을 거 같습니다.

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

Comment on lines +23 to +24
if(j >= coin) {
methods[j] = Math.min(methods[j], methods[j - coin] + 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.

coins을 미리 소트해두면 좀 더 최적화 해볼 수 있을 거 같습니다.

Comment on lines +25 to +26
} else {
// nums[mid] > nums[right] // mid 좌측은 살펴볼 필요가 없음

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.

nums[mid] > nums[right] 조건은 주석으로 쓰기 보단 코드로 나타내는게 더 정확할 거 같습니다. 실제로는 else 문이라 nums[mid] >= nums[right] 에 대한 로직이라 정확히 매치는 안되는 거 같습니다.

Comment on lines +15 to +19
int len = nums.length - 1;
// 중간 지점은 전체 갯 수를 2로 나눈 수로 함. 배열의 크기는 1 이상 5000 이하 이므로 int 커버 됨.

int left = 0;
int right = len;

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.

nit: len은 한번만 사용이 되서 인라인해도 될 거 같습니다.

Comment on lines +21 to +23
while(left < right) {
int mid = (left + right) / 2;
if(nums[mid] < nums[right]) { // mid 우측은 살펴볼 필요가 없음

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.

더 최적화 한다면 if(nums[left] < nums[mid] && nums[mid] < nums[right]) 다음과 같은 로직을 넣어보셔도 좋을 거 같습니다.

Comment on lines +13 to +16
public int maxDepth(TreeNode root) {
if(root == null) return 0;
return 1 + Math.max(maxDepth(root.left), maxDepth(root.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 +36 to +46
public boolean find(
int cursor,
int len,
int curRow,
int curCol,
int maxRow,
int maxCol,
char[][] board,
String word,
boolean[][] visited
) {

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.

파라미터가 다소 많은 거 같아서 줄여보셔도 좋을 거 같아요. 첫번째 파라미터 cursor는 인덱스 값을 가져서 idx 와 같은 네이밍을 고려하셔도 좋을 거 같습니다.

Comment on lines +18 to +20
// visited 배열도 board와 동일하게 [row][col] 크기로 선언
boolean[][] visited = new boolean[maxRow][maxCol];
char startChar = word.charAt(0);

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.

visited 없이 board 에 마킹했다 되돌리는 식으로 사용하시면 보다 간결하게 작성이 되실 거 같습니다.

@dahyeong-yun
dahyeong-yun merged commit 38e4c7b into DaleStudy:main Jul 18, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Jul 18, 2026
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.

5 participants