Skip to content

[Chanz] WEEK 04 Solutions#2753

Merged
parkhojeong merged 8 commits into
DaleStudy:mainfrom
Chanz82:main
Jul 19, 2026
Merged

[Chanz] WEEK 04 Solutions#2753
parkhojeong merged 8 commits into
DaleStudy:mainfrom
Chanz82:main

Conversation

@Chanz82

@Chanz82 Chanz82 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

Chanz82 added 7 commits July 11, 2026 01:24
Implement a method to check if a string is a palindrome, ignoring non-alphanumeric characters and case.
Implement Hamming weight calculation using bit manipulation.
Implement combination sum algorithm to find all unique combinations of candidates that sum to the target.
Implement mergeTwoLists function to merge two sorted linked lists.
Implement depth-first search to calculate maximum depth of a binary tree.
Implement binary search to find the minimum in a rotated sorted array.
Implement depth-first search to find a word in a 2D board.

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking, Depth-First Search
  • 설명: 이 코드는 후보들로 합이 target이 되도록 모든 조합을 재귀적으로 시도하는 백트래킹 방식이다. 또한 가능한 경로를 DFS 방식으로 탐색하며 조건 충족 시 결과를 저장한다.

📊 시간/공간 복잡도 분석

복잡도
Time O(2^n)
Space O(n)

피드백: 백트래킹으로 중복 조합을 제거하지 않고 각 후보를 계속 사용 가능하도록 시작 인덱스를 유지합니다. 종료 조건과 가지치기가 있어도 최악의 경우 지수 시간 복잡도에 근접합니다.

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

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

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

dalestudy Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

📊 Chanz82 님의 학습 현황

이번 주 제출 문제

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

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 2,629 388 3,017 $0.000287
2 1,535 179 1,714 $0.000148
합계 4,164 567 4,731 $0.000435

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Bit Manipulation, Greedy, Binary Search
  • 설명: 주어진 코드는 이진 자리수를 확인해 1의 개수를 세는 방식으로 비트를 직접 순회하며 계산합니다. 비트 연산의 아이디어를 이용한 간단한 카운트지만, 주로 이진 표현의 비트를 다루는 Bit Manipulation에 해당합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(k)
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Hash Map / Hash Set, Greedy
  • 설명: 문자열에서 알파벳/숫자만 제거하고 소문자로 정리한 뒤, 앞뒤를 양끝부터 비교하는 투포인터 방식으로 팔린드롬 여부를 판단합니다. 중간에 필요한 추가 자료구조 없이 양 끝 인덱스로 대등 비교하는 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 공백 제거와 소문자화 후 양방향 탐색으로 팔린드롬 여부를 판단합니다.

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

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

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
  • 설명: 정렬된 배열이 회전되었을 때 중간값과 끝값을 비교해 최소값의 위치를 이분탐색으로 좁혀나가는 패턴으로, O(log n) 성능을 가진다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 4가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: Solution.findMin — Time: O(log n) / Space: O(1)
복잡도
Time O(log n)
Space O(1)

피드백: 중단 조건이 left < right 이고, 매 반복마다 중간값과 오른쪽 끝 값을 비교해 범위를 절반으로 축소합니다.

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

풀이 2: Solution.maxDepth — Time: O(n) / Space: O(h)
복잡도
Time O(n)
Space O(h)

피드백: 재귀적인 DFS로 각 노드를 한 번씩 방문하고 스택 프레임으로 깊이를 추적합니다.

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

풀이 3: Solution.mergeTwoLists — Time: O(n + m) / Space: O(1)
복잡도
Time O(n + m)
Space O(1)

피드백: 비교를 통해 노드를 재배치하여 더미 노드를 가운데에 두고 연결 리스트를 확장합니다.

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

풀이 4: Solution.exist — Time: O(4^(L) * NM) / Space: O(L)
복잡도
Time O(4^(L) * NM)
Space O(L)

피드백: 각 좌표에서 DFS를 진행하고 방문 처리를 위해 문자를 임시로 바꿔 재귀적으로 탐색합니다.

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

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

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
  • 설명: 트리의 각 노드를 방문하며 깊이를 추적하는 재귀 DFS 방식으로 최대 깊이를 구하는 풀이로 해당 패턴에 속합니다.

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 is not listed, Linked List
  • 설명: 리스트를 순회하며 두 리스트의 노드를 차례로 비교해 연결하는 방식으로 구현되어 있어 Two Pointers 패턴에 해당합니다. 또한 결과 리스트를 구성하기 위해 포인터를 앞뒤로 이동시키는 방식으로 구현되어 있습니다.

Comment thread word-search/Chanz82.py

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로 칸을 순회하며 단어의 글자를 매칭하고, 방문한 칸을 임시로 변경 후 되돌리는 방식이 백트래킹 패턴으로 나타납니다. 보드를 시작점마다 탐색하며 방향 탐색을 재귀적으로 수행합니다.

@sonshn
sonshn self-requested a review July 18, 2026 10:21

@sonshn sonshn 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.

이번 주도 고생 많으셨습니다!


dfs(root, 0)
return max_depth

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.

확실히 이 문제에서는 BFS보다는 DFS가 더 좋은 풀이 같네요!

cursor.next = list2

return result.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.

저는 재귀로 풀었는데, 이렇게도 풀 수 있겠네요!

Comment thread word-search/Chanz82.py
for y, cell in enumerate(rows):
if dfs((x, y), 0) == True :
return True
return False

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로 풀 수 있다는 것은 전혀 생각하지 못했네요...! 감사합니다!

@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 +7 to +10
while left < right:
mid = (left + right) // 2

if nums[right] < nums[mid]: # 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.

탐색 중간에 정답으로 판별이 가능한 경우가 있는데 최적화 시도해보셔도 좋을 거 같습니다

Comment on lines +9 to +24
def maxDepth(self, root: Optional[TreeNode]) -> int:

max_depth = 0
def dfs(cur_node, cur_depth):
nonlocal max_depth
if cur_node == None:
return
cur_depth += 1
max_depth = max(max_depth, cur_depth)

dfs(cur_node.left, cur_depth)
dfs(cur_node.right, cur_depth)
return

dfs(root, 0)
return max_depth

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.

개인적으로 외부 변수 max_depth, nonlocal 때문에 그런지 코드 따라가기가 약간 어려웠던거 같습니다. dfs 함수의 리턴 값을 활용하시면 가독성을 많이 올리실 수 있을 거 같습니다.

Comment on lines +18 to +30
while cursor.next:
while list2 and list2.val <= cursor.next.val:
temp_1 = cursor.next
temp_2 = list2.next

cursor.next = list2
list2.next = temp_1
list2 = temp_2

cursor = cursor.next

if list2:
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.

cursor에 어떤 값이 담기고 list2와 어떻게 비교되어서 동작하는건지 따라가기가 조금 어려운 거 같습니다. 스왑 로직도 있고 해서 그런 거 같은데 조금 더 단순하게 풀어보셔도 좋을 거 같습니다.

Comment thread word-search/Chanz82.py
Comment on lines +4 to +26
def dfs(current, word_idx):
x, y = current

if word_idx == len(word):
return True

if x < 0 or x >= len(board) or y < 0 or y >= len(board[0]):
return False

if board[x][y] != word[word_idx] :
return False

tmp = board[x][y]
board[x][y] = '#'

found = (dfs((x-1, y), word_idx+1) or
dfs((x+1, y), word_idx+1) or
dfs((x, y-1), word_idx+1) or
dfs((x, y+1), word_idx+1))

board[x][y] = tmp

return found

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% 정도 나오는데 최적화 시도해보셔도 좋을 거 같습니다. 불필요한 탐색을 안하도록 해보시면 될 거 같아요.

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

3 participants