Skip to content

[okyungjin] WEEK 04 Solutions (최적화)#2759

Merged
okyungjin merged 7 commits into
DaleStudy:mainfrom
okyungjin:main
Jul 19, 2026
Merged

[okyungjin] WEEK 04 Solutions (최적화)#2759
okyungjin merged 7 commits into
DaleStudy:mainfrom
okyungjin:main

Conversation

@okyungjin

@okyungjin okyungjin commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

다른 분들 PR에 있는 내용 참고하여 최적화 적용했습니다.

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

📊 okyungjin 님의 학습 현황

이번 주 제출 문제

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

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 3,301 192 3,493 $0.000242
2 3,412 220 3,632 $0.000259
3 3,412 216 3,628 $0.000257
합계 10,125 628 10,753 $0.000757

@okyungjin

Copy link
Copy Markdown
Contributor Author

@parkhojeong @alphaorderly 코치님들 안녕하세요. 다른 분들 PR 내용 참고해서 최적화 로직을 적용했는데 리뷰 부탁드려도 될까요?

@alphaorderly

Copy link
Copy Markdown
Contributor

사실 너무 꽤나 깔끔하게 잘 하셔서 더이상 말이 필요 없을 정도네요
잘해주셨습니다!

@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 coin-change/okyungjin.py
Comment on lines +23 to +27
# 모든 동전 종류를 확인하여 현재 금액을 만들 수 있는 조합 탐색
for coin in coins:
# coins가 정렬되어 있으므로, cur_amount 보다 동전의 금액이 더 크면 이후는 확인 불필요
if coin > cur_amount:
break

# 둘 중 더 작은 값으로 업데이트
# 1. 기존에 구한 개수
# 2. 현재 동전을 1개 추가해서 만드는 개수
min_coins[cur_amount] = min(min_coins[cur_amount], min_coins[cur_amount - coin] + 1)
# 동전 금액이 현재 금액보다 작거나 같을 때만 유효한 조합으로 간주
if coin <= cur_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.

if coin <= cur_amount 로직을 포문 안에서 계속 돌게 해주신 이유가 있을까요?

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.

원래는 coins를 정렬한 뒤 if coin > cur_amount: break 조기 종료 조건을 사용했었는데요. 코드를 더 간결하게 다듬기 위해 정렬을 없애고 부등호를 뒤집는 방향으로 수정했습니다.

coins 배열 길이가 최대 12라 break 유무에 따른 성능 차이가 크지 않을 것 같아 로직을 간소화해 보았습니다!

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.

사담이지만 그 아래 라인에 있는 min 함수를 제거하니 성능이 훨씬 좋아지더라구요

min_coins[cur_amount] = min(min_coins[cur_amount], min_coins[cur_amount - coin] + 1)

if문 형태로 필요할 때만 할당하도록 하니 런타임 백분위가 30% 올라갔던 것 같습니다.

@alphaorderly alphaorderly Jul 19, 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.

맞아요, max나 min으로 하는게 코드상 보기 좋고 쓰기도 편한게 맞는데
성능은 은근히 차이가 나더라구요
몇몇 문제는 100~200ms 가량 차이나는것도 본적 있어요

Comment on lines +9 to 30
# 트리가 비어있으면 길이는 0
if root is None:
return 0

max_depth = 1

# 스택에 (현재 노드, 노드의 깊이) 튜플을 저장
stack = [(root, 1)]

while stack:
node, cur_depth = stack.pop()

# 현재 노드의 깊이와 저장된 최댓값을 비교하여 갱신
max_depth = max(cur_depth, max_depth)

# 왼쪽 자식 노드가 있다면 현재 깊이 + 1을 하여 스택에 추가
if node.left:
stack.append((node.left, cur_depth + 1))

# 오른쪽 자식 노드가 있다면 현재 깊이 + 1을 하여 스택에 추가
if node.right:
stack.append((node.right, cur_depth + 1))

@parkhojeong parkhojeong Jul 19, 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.

다른 파일들 포함해서 주석을 많이 달아주셨는데 코드만으로 충분한 것들이 많은 것 같아요!

코드를 통해서 최대한 의도를 드러내고 꼭 필요한 상황에만 적어주시는 편이 좋을 거 같아요. 주석도 같이 읽어야 해서 인지적 부하도 올라가고 가독성이 떨어지는 부분도 생기기도 해서요. 특히 코드와 주석이 정확히 일치하지 않는 경우가 생기지 않도록 조심해야 하는 거 같아요.

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 thread word-search/okyungjin.py
Comment on lines +27 to +32
# 빈도수가 더 적은 글자부터 탐색하도록 단어를 뒤집는다
count_first = sum(row.count(word[0]) for row in board)
count_last = sum(row.count(word[-1]) for row in board)

if count_first > count_last:
word = word[::-1]

@parkhojeong parkhojeong Jul 19, 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.

인풋의 패턴을 파악해서 최적화 한다는 점에선 좋은 접근인 거 같습니다. 다만 첫글자와 마지막 글자의 빈도만 비교해서 최적화하는건 특수한 케이스만 커버가 될 거 같아요. 리트코드 채점 데이터셋엔 이 경우가 들어간 거 같더라구요.

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 thread maximum-depth-of-binary-tree/okyungjin.py
Comment thread coin-change/okyungjin.py
Comment thread find-minimum-in-rotated-sorted-array/okyungjin.py
Comment thread maximum-depth-of-binary-tree/okyungjin.py
Comment thread merge-two-sorted-lists/okyungjin.py
Comment thread word-search/okyungjin.py
@okyungjin

Copy link
Copy Markdown
Contributor Author

리뷰 정성스럽게 남겨주셔서 정말 감사드립니다 : ) 시간이 다 되어서 PR은 머지해두도록 하겠습니다!

@okyungjin
okyungjin merged commit 46d6ee8 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