Skip to content

[yuseok89] WEEK 07 Solutions - #2800

Merged
parkhojeong merged 6 commits into
DaleStudy:mainfrom
yuseok89:main
Aug 8, 2026
Merged

[yuseok89] WEEK 07 Solutions#2800
parkhojeong merged 6 commits into
DaleStudy:mainfrom
yuseok89:main

Conversation

@yuseok89

@yuseok89 yuseok89 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

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.

🏷️ 알고리즘 패턴 분석

container-with-most-water/yuseok89.py
# TC: O(N)
# SC: O(1)
class Solution:
    def maxArea(self, height: List[int]) -> int:
        l = 0
        r = len(height) - 1
        max_height = max(height)
        ans = 0

        while l < r:
            ans = max(ans, min(height[l], height[r]) * (r - l))

            if ans > max_height * (r - l):
                return ans

            if height[l] < height[r]:
                l += 1
            else:
                r -= 1

        return ans
  • 패턴: Two Pointers, Greedy
  • 설명: 두 포인터를 양 끝에서 시작해 유효 용량을 계산하고, 더 작은 벽 높이에 맞춰 한쪽을 이동시키며 최댓값을 갱신하는 방식으로 최적해를 찾습니다. 또한 각 단계에서 현재 해와 후보 해를 비교해 더 좋은 방향으로 이동하는 점에서 Greedy 특성을 보입니다.

📊 시간/공간 복잡도 분석

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

🏷️ 알고리즘 패턴 분석

design-add-and-search-words-data-structure/yuseok89.py
class WordDictionary:

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

    def addWord(self, word: str) -> None:
        cur = self.trie

        for c in word:
            if c not in cur:
                cur[c] = {}
            cur = cur[c]

        cur[0] = True

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

        n = len(word)

        def rec(cur: dict, idx: int) -> bool:
            if idx == n:
                return 0 in cur

            if word[idx] == '.':
                for next in cur:
                    if next == 0:
                        continue
                    if rec(cur[next], idx + 1):
                        return True
                return False
            else:
                if word[idx] in cur:
                    return rec(cur[word[idx]], idx + 1)
                else:
                    return False

        return rec(self.trie, 0)
  • 패턴: Trie, Hash Map / Hash Set, Backtracking
  • 설명: 트라이(Trie) 구조로 단어를 저장하고 검색하며, '.' 와일드카드를 재귀적으로 탐색하는 방식이 핵심이다. 부분적으로 탐색 공간 확장을 위한 백트래킹 성격의 재귀가 사용된다.

📊 시간/공간 복잡도 분석

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

풀이 1: WordDictionary.addWord — Time: O(len(word)) / Space: O(total_nodes)
복잡도
Time O(len(word))
Space O(total_nodes)

피드백: 트라이 기반으로 단어를 삽입하고 와일드카드 검색까지 재귀적으로 처리한다.

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

풀이 2: WordDictionary.search — Time: O(len(word) * branching) / Space: O(depth)
복잡도
Time O(len(word) * branching)
Space O(depth)

피드백: '.'가 다수일 때 탐색 공간이 증가하므로 최악의 경우 지수적으로 증가할 수 있다.

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

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

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.

🏷️ 알고리즘 패턴 분석

longest-increasing-subsequence/yuseok89.py
# TC: O(NlogN)
# SC: O(N)
class Solution:
    def lengthOfLIS(self, nums: List[int]) -> int:
        arr = []

        for num in nums:
            if len(arr) == 0 or arr[-1] < num:
                arr.append(num)
            else:
                idx = bisect_left(arr, num)
                arr[idx] = num

        return len(arr)
  • 패턴: Binary Search, Dynamic Programming
  • 설명: 최적 증가 수열 길이는 이진 탐색으로 부분수열의 마지막 원소를 갱신하는 방식으로 구해지며, DP의 최적화와 이진 탐색의 결합으로 해결한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(NlogN) O(n log n)
Space O(N) O(n)

피드백: 이분 탐색 기반 최적화로 LIS를 효율적으로 얻는다.

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

@dalestudy

dalestudy Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

📊 yuseok89 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
longest-substring-without-repeating-characters Medium ✅ 의도한 유형
number-of-islands Medium ✅ 의도한 유형
reverse-linked-list Easy ✅ 의도한 유형
set-matrix-zeroes Medium ⚠️ 유형 불일치
unique-paths Medium ✅ 의도한 유형

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 3,503 425 3,928 $0.000345
2 1,777 218 1,995 $0.000176
3 1,780 241 2,021 $0.000185
합계 7,060 884 7,944 $0.000707

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.

🏷️ 알고리즘 패턴 분석

longest-substring-without-repeating-characters/yuseok89.py
# TC: O(N)
# SC: O(1)
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        seen = set()
        ans = 0
        l, r = 0, 0

        for r in range(0, len(s)):
            c = s[r]

            while c in seen:
                seen.remove(s[l])
                l += 1

            seen.add(c)

            ans = max(ans, r - l + 1)

        return ans
  • 패턴: Sliding Window
  • 설명: 두 포인터(l, r)로 윈도우를 확장/축소하며 중복 문자를 제거하는 방식으로 부분문자열의 길이를 구한다. 해시셋으로 현재 윈도우의 문자를 관리한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(1) O(k)

피드백: 한 방향으로 윈도우를 이동시키며 중복을 제거한다.

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

@yuseok89 yuseok89 moved this to In Review in 리트코드 스터디 8기 Aug 6, 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.

🏷️ 알고리즘 패턴 분석

number-of-islands/yuseok89.py
# TC: O(NM)
# SC: O(NM)
class Solution:
    def numIslands(self, grid: List[List[str]]) -> int:
        ans = 0
        n = len(grid)
        m = len(grid[0])

        dirs = [[-1, 0], [1, 0], [0, -1], [0, 1]]

        def fill(row: int, col: int):
            grid[row][col] = '0'

            for dir in dirs:
                new_row = row + dir[0]
                new_col = col + dir[1]

                if 0 <= new_row < n and 0 <= new_col < m and grid[new_row][new_col] == '1':
                    fill(new_row, new_col)

        for i in range(0, n):
            for j in range(0, m):
                if grid[i][j] == '1':
                    fill(i, j)
                    ans += 1

        return ans
  • 패턴: Depth-First Search, Hash Map / Hash Set
  • 설명: 섬의 연결 여부를 재귀적으로 탐색하며 인접한 땅을 방문 처리합니다. 재귀로 인접 칸을 탐색하는 DFS 방식이 핵심이며, 방문 여부를 그래드(grid) 값을 바꿔 표시합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(NM) O(n*m)
Space O(NM) O(n*m)

피드백: 모든 셀을 한 번씩 방문하고 인접하던 땅을 탐색한다.

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

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.

🏷️ 알고리즘 패턴 분석

reverse-linked-list/yuseok89.py
# TC: O(N)
# SC: O(1)
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:

        prev = None
        cur = head

        while cur:
            next = cur.next
            cur.next = prev
            prev = cur
            cur = next

        return prev
  • 패턴: Two Pointers, Linked List
  • 설명: 해당 코드는 한 노드를 지나며 포인터 두 개를 사용해 연결 리스트를 역순으로 뒤집는다. 각 노드를 방문하며 앞의 포인터를 차례로 뒤로 보냄으로써 제자리에서 역전하는 패턴이다.

📊 시간/공간 복잡도 분석

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

🏷️ 알고리즘 패턴 분석

set-matrix-zeroes/yuseok89.py
# TC: O(NM)
# SC: O(N+M)
class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """

        n = len(matrix)
        m = len(matrix[0])

        row_set = set()
        col_set = set()

        for row in range(0, n):
            for col in range(0, m):
                if matrix[row][col] == 0:
                    row_set.add(row)
                    col_set.add(col)

        for row in range(0, n):
            for col in range(0, m):
                if row in row_set or col in col_set:
                    matrix[row][col] = 0
  • 패턴: Hash Map / Hash Set, Greedy, Two Pointers, Dynamic Programming, Sliding Window, Binary Search, Monotonic Stack, Heap / Priority Queue, BFS, DFS, Backtracking, Divide and Conquer, Union Find, Trie, Bit Manipulation
  • 설명: 행렬에서 0인 위치를 저장해두고, 저장된 행과 열에 해당하는 원소를 0으로 설정한다. 해시 셋을 이용해 인덱스 기록 패턴이 활용되며 공간 절약 없이 직관적으로 문제를 해결한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(NM) O(n*m)
Space O(N+M) O(n + m)

피드백: 필요한 행과 열의 인덱스를 저장하기 위해 두 개의 집합을 사용하고, 이후 전체 매트릭스를 순회하며 0으로 설정한다.

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

Comment thread unique-paths/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.

🏷️ 알고리즘 패턴 분석

unique-paths/yuseok89.py
# TC: O(NM)
# SC: O(N)
class Solution:
    def uniquePaths(self, m: int, n: int) -> int:

        cnt = [0] * n
        cnt[0] = 1

        for i in range(0, m):
            for j in range(1, n):
                cnt[j] += cnt[j - 1]

        return cnt[n - 1];
  • 패턴: Dynamic Programming, Greedy, Two Pointers
  • 설명: 수평 미로처럼 행렬의 경로를 누적합으로 계산하는 DP 패턴으로, 메모리 절약을 위해 1차 배열로 최적화하는 기법이 보입니다. 각 셀의 경로 수를 왼쪽 셀과 위 셀의 합으로 구하는 전형적인 DP 접근입니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(NM) O(m*n)
Space O(N) O(n)

피드백: 1차원 DP 배열을 사용해 현재 열의 누적 경로 수를 다음 열로 업데이트한다.

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

@daehyun99
daehyun99 self-requested a review August 7, 2026 07:53

@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 reverse-linked-list/yuseok89.py Outdated
Comment thread unique-paths/yuseok89.py Outdated
Comment thread longest-substring-without-repeating-characters/yuseok89.py Outdated
Comment thread longest-substring-without-repeating-characters/yuseok89.py Outdated
Comment thread longest-substring-without-repeating-characters/yuseok89.py Outdated

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.

🏷️ 알고리즘 패턴 분석

longest-substring-without-repeating-characters/yuseok89.py
# TC: O(N)
# SC: O(K)
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        idx_map = {}
        start = 0
        ans = 0

        for end in range(len(s)):
            c = s[end]
            if c in idx_map and start <= idx_map[c]:
                start = idx_map[c] + 1
            else:
                ans = max(ans, end - start + 1)

            idx_map[c] = end

        return ans
  • 패턴: Hash Map / Hash Set, Two Pointers
  • 설명: 문자열에서 중복을 확인하며 좌측 포인터를 앞으로 이동시키는 방식으로 부분 문자열의 최대 길이를 찾는다. 해시 맵으로 최근 위치를 추적하고, 두 포인터가 존재하는 패턴이 핵심이다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(K) O(min(n, charset))

피드백: 문자 위치를 맵에 저장하고, 현재 문자 재등장 시 윈도우의 시작 위치를 갱신한다. 한 루프에서 모든 문자를 한 번씩 처리한다.

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

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.

🏷️ 알고리즘 패턴 분석

reverse-linked-list/yuseok89.py
# TC: O(N)
# SC: O(1)
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:

        prev = None
        cur = head

        while cur:
            nxt = cur.next
            cur.next = prev
            prev = cur
            cur = nxt

        return prev
  • 패턴: Two Pointers, Reverse
  • 설명: 연결 리스트를 역순으로 뒤집기 위해 선두와 현재 지점을 두고 포인터를 교체하는 방식으로 한 방향으로 진행하는 패턴입니다. 공간복잡도 O(1)로 순회하며 링크를 역태깅합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(N) O(n)
Space O(1) O(1)

피드백: 세 개의 포인터(prev, cur, nxt)를 이용해 각 노드의 next를 역방향으로 가리키게 한다.

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

Comment thread unique-paths/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.

🏷️ 알고리즘 패턴 분석

unique-paths/yuseok89.py
# TC: O(NM)
# SC: O(N)
class Solution:
    def uniquePaths(self, m: int, n: int) -> int:

        cnt = [0] * n
        cnt[0] = 1

        for i in range(0, m):
            for j in range(1, n):
                cnt[j] += cnt[j - 1]

        return cnt[n - 1]
  • 패턴: Dynamic Programming, Greedy
  • 설명: 이 코드는 m x n 격자에서 최단 경로의 수를 누적합 방식으로 구하는 동적 프로그래밍 패턴이며, 공간을 절약하기 위해 1차원 배열로 상태를 갱신합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(NM) O(m * n)
Space O(N) O(n)

피드백: 네 번째 줄에서 새로운 열의 값을 이전 열의 값들로 갱신하며 메모리 사용을 최소화했다.

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

@yuseok89
yuseok89 requested a review from parkhojeong August 8, 2026 05:27

@daehyun99 daehyun99 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 +6 to +7
n = len(grid)
m = len(grid[0])

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.

참고로만 말씀드리면, 문제에서의 mn의 의미와 반대로네요.

Comment on lines +9 to +10
n = len(matrix)
m = len(matrix[0])

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.

참고로만 말씀드리면, 문제에서의 mn의 의미와 반대로네요.

여기도요!

Comment thread unique-paths/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.

오 이런 방법으로도 풀 수 있군요! 많이 배워갑니다.

@parkhojeong
parkhojeong merged commit 9f34535 into DaleStudy:main Aug 8, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Review to Completed in 리트코드 스터디 8기 Aug 8, 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