Skip to content

[ICE0208] WEEK 05 Solutions#2774

Merged
ICE0208 merged 5 commits into
DaleStudy:mainfrom
ICE0208:week05
Jul 25, 2026
Merged

[ICE0208] WEEK 05 Solutions#2774
ICE0208 merged 5 commits into
DaleStudy:mainfrom
ICE0208:week05

Conversation

@ICE0208

@ICE0208 ICE0208 commented Jul 25, 2026

Copy link
Copy Markdown
Member

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📊 ICE0208 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
best-time-to-buy-and-sell-stock Easy ✅ 의도한 유형
encode-and-decode-strings Medium ✅ 의도한 유형
group-anagrams Medium ✅ 의도한 유형
implement-trie-prefix-tree Medium ✅ 의도한 유형
word-break Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

카테고리 진행도 완료
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 1,440 133 1,573 $0.000125
2 2,012 182 2,194 $0.000173
3 2,411 213 2,624 $0.000206
4 2,411 278 2,689 $0.000232
합계 8,274 806 9,080 $0.000736

@ICE0208 ICE0208 moved this from Solving to In Review in 리트코드 스터디 8기 Jul 25, 2026
@njngwn
njngwn self-requested a review July 25, 2026 09:28
@njngwn

njngwn commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

전체적으로 따로 코멘트를 달 게 없다고 느낄 정도로 잘 쓰여진 코드네요. 깔끔하고 주석도 설명이 잘 되어있어서 이해하기 좋았습니다. 수고 많으셨습니다!!

@njngwn njngwn closed this Jul 25, 2026
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Jul 25, 2026
@njngwn njngwn reopened this Jul 25, 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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy
  • 설명: 주가의 최소값으로 매수하고 현재 시점의 이익을 비교하며 가장 큰 이익을 선택하는 단순한 한 방향 탐욕적 접근이다. 별도의 보조 데이터 구조 없이 순회하는 O(n) 방식으로 최적 해를 구한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Greedy, Dynamic Programming, Hash Map / Hash Set, Divide and Conquer, Binary Search, Monotonic Stack, Heap / Priority Queue, BFS, DFS, Backtracking, Union Find, Trie, Bit Manipulation, Sliding Window, Fast & Slow Pointers, DFS, Greedy, Dynamic Programming
  • 설명: 문자열 인코딩/디코딩은 문자열의 길이와 구분자를 이용해 데이터를 직렬화하는 방식이다. 인코딩은 간단한 선형 순회로 길이와 문자열을 결합하고, 디코딩은 구분자를 따라 길이를 읽고 해당 길이의 문자열을 추출한다. 전형적으로 순차 탐색과 문자열 파싱의 패턴이다.

📊 시간/공간 복잡도 분석

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

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

피드백: 모든 문자열 길이의 합 n에 비례하는 시간과 공간 복잡도이다.

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

풀이 2: Solution.decode — Time: O(n) / Space: O(n)
복잡도
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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Two Pointers, Greedy, Dynamic Programming, Divide and Conquer, Backtracking, Sliding Window, Binary Search, Stack / Priority Queue, Trie, Bit Manipulation, Union Find, BFS, DFS, Monotonic Stack, Heap / Priority Queue
  • 설명: 주어진 코드는 해시맵으로 키(문자빈도 배열)를 매핑해 애너그램끼리 그룹화한다. 각 단어의 문자 빈도 계산은 고유 키를 만들고, 같은 키를 가진 단어를 같은 그룹으로 모으는 방식이다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(S) O(n * k)
Space O(n) O(n * k)

피드백: 모든 문자열을 한 번씩 처리하고 빈도 배열을 키로 사용한다.

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

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
  • 설명: 주어진 코드는 Trie(접두어 트리) 구조를 구현하여 단어 삽입, 검색, 접두사 검색을 수행합니다. 자식 노드를 사전으로 관리하고, 각 노드에 단어 종료 여부를 표시하는 전형적인 Trie 패턴입니다.

📊 시간/공간 복잡도 분석

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

풀이 1: Trie.insert — Time: O(m) / Space: O(m)
복잡도
Time O(m)
Space O(m)

피드백: 새 단어를 추가할 때 길이 m에 비례하는 시간과 공간을 사용한다.

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

풀이 2: Trie.search — Time: O(m) / Space: O(1)
복잡도
Time O(m)
Space O(1)

피드백: 경로 탐색과 끝 단어 여부 확인으로 판단한다.

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

풀이 3: Trie.startsWith — Time: O(m) / Space: O(1)
복잡도
Time O(m)
Space O(1)

피드백: 접두사 여부는 경로 존재 여부로 충분하다.

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

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

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Hash Map / Hash Set, Backtracking
  • 설명: 단어 조합 여부를 재귀적으로 탐색하고, 사전 단어를 해시셋으로 빠르게 확인하며, 중간 결과를 캐시로 저장해 중복 탐색을 줄이는 패턴이 사용됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 동일 부분문제 재사용으로 중복 계산을 제거한다.

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

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

from typing import List


class Solution:

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
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

원래 알고리즘 문제 풀이는 파이썬으로만 했는데, 최근 스프링 백엔드 쪽을 공부하고 있어서 자바와 좀 더 친해지고자 이번 알고리즘 문제는 자바로 풀고 있습니다...만! 이번 주는 시간이 없어 벼락치기로 문제를 풀다 보니 어쩔 수 없이 파이썬으로 빠르게 풀고 제출했습니다. ㅎㅎ

@@ -0,0 +1,49 @@
from typing import List

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.

파이썬 3.9+ 부터는 선언을 안해도 list[str]을 쓸 수 있다고 합니다!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그렇군요
알려주셔서 감사합니다!

Comment on lines +2 to +8
/**
* 오늘 주식을 판매한다고 가정하면,
* 이전 날짜 중 가장 낮은 가격에 구매했을 때 최대 이익을 얻을 수 있다.
* 배열을 순회하면서 최저 가격과 최대 이익을 계속 갱신한다.
*
* 시간 복잡도: O(n)
* 공간 복잡도: 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.

주석도 설명이 아주 잘되어있고, 코드도 정말 깔끔하네요. 수고하셨습니다!!

String key = Arrays.toString(frequency);

// 같은 키를 가진 문자열을 동일한 그룹에 추가한다.
groups.computeIfAbsent(key, ignored -> new ArrayList<>())

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.

코드 수를 줄일 수 있어서 좋네요. 배워갑니다!

@ICE0208

ICE0208 commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

@njngwn 꼼꼼한 코드리뷰 감사합니다☺️

@ICE0208
ICE0208 merged commit f4879f9 into DaleStudy:main Jul 25, 2026
4 checks passed

@dahyeong-yun dahyeong-yun 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.

자바 코드, 파이썬 코드가 같이 있어서 비교해서 보기 좋았습니다. 주석도 적절히 있고 코드 개행도 신경써서 나눠주셔서 보기 편했네요. 잘 보고 갑니다 👍🏼

int[] frequency = new int[26];

// 알파벳별 등장 횟수를 계산한다.
for (int i = 0; i < word.length(); i++) {

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/ICE0208.py
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
word_set = set(wordDict)

@cache

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
Member Author

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

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

3 participants