Skip to content

[yuseok89] WEEK 05 Solutions#2765

Open
yuseok89 wants to merge 7 commits into
DaleStudy:mainfrom
yuseok89:main
Open

[yuseok89] WEEK 05 Solutions#2765
yuseok89 wants to merge 7 commits into
DaleStudy:mainfrom
yuseok89:main

Conversation

@yuseok89

@yuseok89 yuseok89 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

📊 yuseok89 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
best-time-to-buy-and-sell-stock Easy ✅ 의도한 유형
group-anagrams Medium ✅ 의도한 유형
implement-trie-prefix-tree Medium ✅ 의도한 유형
word-break Medium ⚠️ 유형 불일치

누적 학습 요약

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

문제 풀이 현황

카테고리 진행도 완료
Array ■■■■□□□ 6 / 10 (Medium 4, Easy 2)
Dynamic Programming ■■■□□□□ 5 / 11 (Easy 1, Medium 4)
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)
Tree ■□□□□□□ 2 / 14 (Easy 1, Medium 1)
Graph ■□□□□□□ 1 / 8 (Medium 1)
Interval □□□□□□□ 0 / 5 ← 아직 시작 안 함

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 580 101 681 $0.000069
2 1,443 197 1,640 $0.000151
3 1,443 224 1,667 $0.000162
4 1,443 191 1,634 $0.000149
5 1,427 155 1,582 $0.000133
합계 6,336 868 7,204 $0.000664

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.

prices[1:]
와 같이 하시면 보기엔 정말 좋은데 말이죠
파이썬 슬라이싱은 말 그대로 배열을 하나 더 만들어서 사용하는거라 이 간단한 과정에만 O(N)의 시간이 소요되어요!

파이썬 시간복잡도

Get slice 부분을 보시면 O(k) 라는것을 알수 있죠

그래서 좀 귀찮으시더라도

range(1, len(prices))

를 쓰시는게 나으실거에요!

물론 지금같은 경우는 전체 시간복잡도가 O(N)이고 저 연산은 단 한번 실행되니 시간복잡도 자체에는 큰 영향을 주진 않겠지만

for loop 안에서 써야하는 일이 생긴다면 좀 다르겠죠

word-break 문제에서 이부분을 잘 생각해 다른방식으로 최적화 할수 있는 부분이 있으니 한번 생각하면서 해보시면 좋을것 같네요!

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.

그리고
best time to buy and sell stock, 즉 해당 문제는
뒤에 로마 숫자를 붙혀서 1, 2, 3, 4, 5 총 다섯종류가 있는데요
dp 연습하기에 정말 괜찮은 문제라고 생각해서
2번문제
II는 한번 풀어보시길 추천드려요!

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.

감사합니다. 많이 배웁니다.
로직상 제거해도 괜찮고, range 보다 미묘하게 슬라이스 제거한 것이 빨라, 슬라이스 제거 버전으로 수정했습니다.

@yuseok89 yuseok89 moved this from Solving to In Review in 리트코드 스터디 8기 Jul 21, 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 +9 to +10
max_profit = max(max_profit, price - min_until_now)
min_until_now = min(min_until_now, price)

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를 사용하면 오버헤드가 있어서 더 최적화 한다면 직접 비교해서 업데이트 하는 식으로 해볼 수 있을 거 같습니다.

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-break/yuseok89.py Outdated
Comment on lines +16 to +22
v = set()

def rec(cur):
if cur in v:
return False

v.add(cur)

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

v는 무슨 약어일까요?

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.

visited 입니다.. ㅎ 너무 줄였네요..

Comment thread word-break/yuseok89.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.

문제의 핵심적인 부분만 딱 캐치해서 푸신 거 같습니다. 아이디어는 어떻게 얻으셨는지 궁금하네요. 비슷하게 접근해서 푸셨던 문제나 경험이 있으실까요?

@yuseok89 yuseok89 Jul 24, 2026

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 thread word-break/yuseok89.py Outdated
Comment on lines +1 to +2
#TC: O()
#SC: O()

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-break/yuseok89.py Outdated
Comment on lines +27 to +29
for l in range(min_len, max_len + 1):
if len(cur) < l:
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.

min_len~max_len 범위라 존재하지 않는 len도 탐색하네요.

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, 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Dynamic Programming
  • 설명: 주가의 최솟값을 추적하며 최대 이익을 계산하는 방식으로, 한 번의 순회로 최적해를 구하는 그리디 패턴에 해당합니다. DP의 최솟값 상태를 이용한 최적해 결정으로도 간주될 수 있습니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Sorting
  • 설명: 글자들을 정렬한 문자열을 키로 해시맵에 그룹화하는 방식으로 패턴은 해시 맵과 정렬을 활용한 그룹화이다. 문자열 집합을 키로 묶는 전형적인 해시 기반 그리드/그룹화 문제이다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N * LlogL) O(n * k log k)
Space O(N * L) O(n * k)

피드백: 각 문자열의 길이 k에 대해 정렬 비용이 필요하지만, 총 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Trie, Hash Map / Hash Set
  • 설명: 트라이 입력 문자열의 각 문자로 노드를 따라가며 삽입·검색을 수행하는 구조로, 접두어 검색도 가능하게 한다. 해시 맵 형태의 자식 노드 저장으로 동적 트라이를 구현한 패턴이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(m)
Space O(alphabet_size * m)

피드백: 각 트라이 노드는 해시맵으로 자식 노드를 관리하며, 단어 길이 m에 비례한 시간과 공간이 필요하다.

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

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

Comment thread word-break/yuseok89.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking, Dynamic Programming, Hash Map / Hash Set
  • 설명: 코드는 재귀적 백트래킹으로 가능한 단어 조합을 탐색합니다. 단어 길이 집합과 사전에 기반한 탐색으로 중복 서브문제 재방문을 방지하기 위해 방문 집합을 사용하여 가지치기를 수행합니다.

📊 시간/공간 복잡도 분석

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

피드백: 단어 길이 구간을 기반으로 재귀 탐색과 방문 기록으로 중복 계산을 피한다.

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

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

@yuseok89
yuseok89 requested a review from parkhojeong July 24, 2026 14:58
# SC: O(L * N)
class TrieNode:
def __init__(self):
self.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.

요건 타입 힌트를 명확하게 지정해주면 더 좋을 거 같습니다.

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