Skip to content

[sangbeenmoon] WEEK 05 Solutions#2776

Open
sangbeenmoon wants to merge 15 commits into
DaleStudy:mainfrom
sangbeenmoon:main
Open

[sangbeenmoon] WEEK 05 Solutions#2776
sangbeenmoon wants to merge 15 commits into
DaleStudy:mainfrom
sangbeenmoon:main

Conversation

@sangbeenmoon

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@dalestudy

dalestudy Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📊 sangbeenmoon 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
group-anagrams Medium ✅ 의도한 유형
implement-trie-prefix-tree Medium ✅ 의도한 유형
word-break Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,626 137 1,763 $0.000136

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, Dynamic Programming
  • 설명: 두 코드 모두 문자열을 정렬한 값을 키로 사용하여 그룹을 묶는 방식으로 해시맵(딕셔너리)을 활용합니다. 첫 번째는 방문 배열과 중복 판단으로 묶고, 두 번째는 해시 맵에 리스트를 누적합니다. 패턴은 해시 기반 그룹화에 해당합니다.

📊 시간/공간 복잡도 분석

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Trie
  • 설명: 트라이 구조를 이용한 문자열 저장 및 검색 구현으로 패턴은 Trie입니다. insert, search, startsWith를 재귀적으로 노드를 따라가며 동작합니다.

📊 시간/공간 복잡도 분석

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

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

피드백: 재귀적으로 자식 노드를 따라가고 새 노드를 생성하는 방식으로 삽입이 진행된다.

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

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

피드백: 재귀적 검색으로 단어의 존재를 확인한다.

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

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

피드백: 재귀적으로 접두사를 따라가며 존재 여부를 판단한다.

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

풀이 4: Trie — Time: O(1) / Space: O(1)
복잡도
Time O(1)
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, Backtracking, Hash Map / Hash Set
  • 설명: 초기 풀이 부분은 재귀와 가지치기, 중복 방문 방지를 통해 가능 여부를 탐색하는 백트래킹 성격이다. 두 번째 부분은 DP를 이용한 메모이제이션으로 구간 시작 위치의 가능성을 기초로 결과를 도출한다. 또한 사전 형태로 단어를 빠르게 확인하기 위해 해시 맵을 사용한다.

📊 시간/공간 복잡도 분석

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

피드백: 초기 실패한 풀이와 달리 dp를 활용해 중복 계산을 제거하려는 시도가 보인다.

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

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

Comment on lines +45 to +51
if sorted_target in d:
group = d[sorted_target]
group.append(target)
d[sorted_target] = group.copy()
else:
group = [target]
d[sorted_target] = group.copy()

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 sorted_target in d:
            d[sorted_target].append(target)
        else:
            d[sorted_target] = [target]

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는 의미를 모르겠어요

for candidate in d.values():
answer.append(candidate)

return answer

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.

list(d.values())

이렇게 리스트로 형변환 하시면 answer 없이 바로 가능하세요

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

수고하셨습니다. 고민해보실만한 커멘트 몇가지 남겼습니다.

class TrieNode:

def __init__(self):
self.d = {}

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.

d가 무슨 약어일까요?

class Solution:
def wordBreak(self, s: str, wordDict: List[str]) -> bool:

d = {}

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 +48 to +51
d[sorted_target] = group.copy()
else:
group = [target]
d[sorted_target] = group.copy()

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 쓰신 이유가 있을까요?

Comment on lines +20 to +29
node.insert(word[1:])

def search(self, word):
if word == "":
return self.is_end

target = word[0]

if target in self.d:
return self.d[target].search(word[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.

[1:]이 O(n)이라 현재 insert, search에서 탐색 성능이 좋지 않은 거 같습니다. [1:]을 사용하지 않고 구현해보시면 좋을 거 같습니다.

Comment on lines +45 to +57
class Trie:

def __init__(self):
self.root = TrieNode()

def insert(self, word: str) -> None:
self.root.insert(word)

def search(self, word: str) -> bool:
return self.root.search(word)

def startsWith(self, prefix: str) -> bool:
return self.root.startsWith(prefix)

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에는 구현이 없고 TrieNode에 모든 구현을 하신 이유가 있을까요?

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