Skip to content

[daehyun99] WEEK02 solutions#2687

Open
daehyun99 wants to merge 4 commits into
DaleStudy:mainfrom
daehyun99:W2
Open

[daehyun99] WEEK02 solutions#2687
daehyun99 wants to merge 4 commits into
DaleStudy:mainfrom
daehyun99:W2

Conversation

@daehyun99

@daehyun99 daehyun99 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@daehyun99 daehyun99 self-assigned this Jun 29, 2026
@daehyun99 daehyun99 marked this pull request as ready for review June 29, 2026 15:31
@github-actions github-actions Bot added the py label Jun 29, 2026
@dalestudy

dalestudy Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

📊 daehyun99 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
3sum Medium ✅ 의도한 유형
climbing-stairs Easy ⚠️ 유형 불일치
product-of-array-except-self Medium ⚠️ 유형 불일치
valid-anagram Easy ✅ 의도한 유형
validate-binary-search-tree Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 300 44 344 $0.000033
2 640 107 747 $0.000075
3 989 140 1,129 $0.000105
4 1,909 230 2,139 $0.000187
합계 3,838 521 4,359 $0.000400

@jthw1005 jthw1005 self-requested a review June 29, 2026 19:41

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.

collections 의 Counter가 기본적으로 defaultdict(int) 처럼 없는 키값에 대해 0을 보낸다는것을 알고 계실까요?
그걸 쓰시면 훨씬 간단하게 작성하실수 있으실거에요!

Comment thread 3sum/daehyun99.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Sorting
  • 설명: 주 코드의 핵심은 이중 포인터(l, r)를 이용해 정렬된 배열에서 합이 0이 되도록 찾는 구조로, 중복 제거를 위해 포인터 이동 시건을 사용한다. 이는 Two Pointers 패턴의 대표적 예이다.

📊 시간/공간 복잡도 분석

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Greedy
  • 설명: 주어진 코드는 피보나치 형태의 계단 오르기 문제를 다양한 조합으로 세는 방식으로 구현되며, DP의 기본 아이디어(부분 문제의 합)와 탐색적 접근(그리디형으로 특정 단계의 선택 분기)을 통해 해를 구한다.

📊 시간/공간 복잡도 분석

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

피드백: 각 단계의 경우의 수를 상태로 유지해 빠르게 누적하는 방식으로 구현되었으나, 현재 구현은 직관적이지 않을 수 있다.

개선 제안: 속도와 가독성을 위해 간단한 피보나치 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Prefix/Suffix Product (a.k.a. product of array except self) pattern cannot be generic name, Hash Map / Hash Set, Division and Edge Case Handling
  • 설명: 배열 전체 곱을 한 번에 구한 뒤 각 원소를 나누는 방식과 0의 위치를 관리하는 방식으로 문제를 해결한다. 0의 개수에 따라 결과를 다르게 반환하는 로직은 예외 처리 패턴에 해당한다.

📊 시간/공간 복잡도 분석

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Two Pointers, Greedy
  • 설명: 두 문자열의 문자 빈도를 해시맵으로 합 비교하는 방식으로 동작하며, 서로 다른 문자의 개수를 빠르게 확인해 후보를 제거합니다. 두 포인터처럼 zip으로 한 글자씩 짝을 맞추는 느낌도 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 카운트 차이를 이용해 한 번의 순회로 결과를 판정한다. 간단하고 빠른 방법이다.

개선 제안: 필요 없을 때는 defaultdict 사용 대신 배열 인덱스 기반 카운트로 더 빠르게 구현 가능.

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

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
  • 설명: BST 검증 문제에서 트리를 재귀적으로 순회하며 각 노드의 값이 왼쪽/오른쪽 서브트리의 범위 제약을 만족하는지 확인한다. 재귀적 탐색(DFS)으로 자식 노드의 허용 범위를 좁혀 가는 방식이다.

📊 시간/공간 복잡도 분석

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

피드백: 좌우 자식 노드에 대해 상한/하한 값을 전달하는 방식으로 중복 포함 여부를 올바르게 판단한다.

개선 제안: 스택을 이용한 비재귀 구현으로 재귀 깊이를 제어할 수 있다.

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

@daehyun99 daehyun99 moved this from Solving to In Review in 리트코드 스터디 8기 Jul 3, 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 thread 3sum/daehyun99.py
Comment on lines +19 to +25
else:
res.append([a, nums[l], nums[r]])
l += 1
r -= 1
while nums[l] == nums[l - 1] and l < r:
l += 1
return res

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.

while 문 사용해서 스킵하는 로직이 r 은 빼신 이유가 궁금하네요!

그리고 l < r 평가식을 and 조건 앞쪽에 두는게 안전할 거 같습니다!

Comment on lines +2 to +19
def climbStairs(self, n: int) -> int:
one_count = n
two_count = 0
total_count = 0

while one_count >=0 and two_count >=0:
# 조합
total = one_count + two_count

count = 1
for i in range(two_count):
count *= total - i
for i in range(two_count, 0, -1):
count /= i
total_count += count

one_count -=2
two_count +=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.

dp를 사용하시면 좀더 직관적인 코드로 개선해볼 수 있을 거 같습니다!

Comment on lines +2 to +18
def productExceptSelf(self, nums: List[int]) -> List[int]:
product = 1
zero_pos = set()

for i in range(len(nums)):
num = nums[i]
if num != 0:
product *= num
else:
zero_pos.add(i)

if len(zero_pos) >= 2:
return [0 for num in nums]
elif len(zero_pos) == 1:
return [0 if i not in zero_pos else product for i in range(len(nums))]
else:
return [int(product / num) for num in nums]

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.

문제에서 division을 사용하지 않고 풀도록 나와있어서 곱셈만을 이용해서 풀어보시면 좋을 거 같습니다 :)

Comment on lines +9 to +20
def isValidBST(self, root: Optional[TreeNode]) -> bool:
def valid(node, left, right):
if not node:
return True
if not (left < node.val < right):
return False

return (
valid(node.left, left, node.val) and
valid(node.right, node.val, right)
)
return valid(root, float("-inf"), float("inf"))

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.

가독성이 좋은 코드인 거 같습니다 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants