Skip to content

[njngwn] WEEK 09 Solutions - #2828

Merged
njngwn merged 4 commits into
DaleStudy:mainfrom
njngwn:week09
Aug 22, 2026
Merged

[njngwn] WEEK 09 Solutions#2828
njngwn merged 4 commits into
DaleStudy:mainfrom
njngwn:week09

Conversation

@njngwn

@njngwn njngwn commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

답안 제출 문제

작성자 체크 리스트

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

검토자 체크 리스트

Important

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

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

@njngwn njngwn self-assigned this Aug 21, 2026
@dalestudy

dalestudy Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

⚠️ Week 설정이 누락되었습니다

프로젝트에서 Week를 설정해주세요!

설정 방법

  1. PR 우측의 Projects 섹션에서 리트코드 스터디 옆 드롭다운(▼) 클릭
  2. 현재 주차를 선택해주세요 (예: Week 14(current) 또는 Week 14)

📚 자세한 가이드 보기


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

@github-actions github-actions Bot added the py label Aug 21, 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.

🏷️ 알고리즘 패턴 분석

linked-list-cycle/njngwn.py
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    # Time Complexity: O(n)
    # Space Complexity: O(1)
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        if not head or not head.next:
            return False

        slow = fast = head
        while fast and fast.next:
            slow = slow.next
            fast = fast.next.next
            if slow == fast:
                return True

        return False
  • 패턴: Fast & Slow Pointers, Two Pointers
  • 설명: 일반적으로 고정 포인터와 빠른 포인터를 이용한 사이클 여부 판단으로 Fast & Slow Pointers 패턴(일명 플로이드 순환 탐지)을 사용합니다. 두 포인터의 이동 속도 차이로 사이클 존재 여부를 확인합니다.

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.

🏷️ 알고리즘 패턴 분석

maximum-product-subarray/njngwn.py
class Solution:
    # Time Complexity: O(n), n: nums.length
    # Space Complexity: O(1)
    def maxProduct(self, nums: List[int]) -> int:
        n, res = len(nums), nums[0]
        prefix, suffix = 1, 1

        for i in range(n):
            prefix = nums[i] * (prefix or 1)
            suffix = nums[n-1-i] * (suffix or 1)
            res = max(res, max(prefix, suffix))

        return res
  • 패턴: Two Pointers, Greedy, Dynamic Programming
  • 설명: 배열의 연속 부분배수 최대를 위해 양 끝부터 곱을 누적하는 접근으로 두 포인터가 양쪽에서 진행되며, 특정 위치의 곱의 최대를 갱신하는 구조입니다. 공통 부분구간을 제거하며 최댓값을 찾는 형태로 구현됩니다.

@dalestudy

dalestudy Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

📊 njngwn 님의 학습 현황

이번 주 제출 문제

문제 난이도 유형 분석
linked-list-cycle Easy ✅ 의도한 유형
maximum-product-subarray Medium ✅ 의도한 유형
minimum-window-substring Hard ✅ 의도한 유형
pacific-atlantic-water-flow Medium ⚠️ 유형 불일치

누적 학습 요약

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

문제 풀이 현황

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

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

🔢 API 사용량 (gpt-5-nano)
요청 입력 토큰 출력 토큰 합계 비용
1 1,156 144 1,300 $0.000115
2 1,771 202 1,973 $0.000169
합계 2,927 346 3,273 $0.000285

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.

🏷️ 알고리즘 패턴 분석

minimum-window-substring/njngwn.py
from collections import Counter


class Solution:
    # Time Complexity: O(n), n: s.length
    # Space Complexity: O(1) (as s and t consist of uppercase and lowercase letters. -> fixed value)
    def minWindow(self, s: str, t: str) -> str:
        if len(s) < len(t):
            return ""

        left, min_len = 0, float('inf')
        target, window = Counter(t), Counter()
        required, satisfied = len(target), 0
        min_start = 0

        for right, ch in enumerate(s):  # expand the window
            window[ch] += 1
            if ch in target and window[ch] == target[ch]:
                satisfied += 1

            # shrink the window
            while left <= right and required == satisfied:
                if right - left + 1 < min_len:
                    min_start = left
                    min_len = right - left + 1

                left_ch = s[left]
                window[left_ch] -= 1
                if left_ch in target and window[left_ch] < target[left_ch]:
                    satisfied -= 1

                left += 1

        return "" if min_len == float('inf') else s[min_start: min_start + min_len]
  • 패턴: Sliding Window, Hash Map / Hash Set
  • 설명: 문자열에서 부분 문자열 창(window)을 좌우로 확장하고 축소하는 방식으로 최적의 길이를 찾는 전형적 Sliding Window 패턴이며, Counter를 사용해 각 문자 등장 여부를 추적하므로 Hash Map 사용 패턴도 함께 보입니다.

@sangbeenmoon
sangbeenmoon self-requested a review August 21, 2026 13:54

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.

🏷️ 알고리즘 패턴 분석

pacific-atlantic-water-flow/njngwn.py
from collections import deque

class Solution:
    # Time Complexity: O(n*m), n: len(heights), m: len(heights[0])
    # Space Complexity: O(n*m), n: len(heights), m: len(heights[0])
    def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:
        ROWS, COLS = len(heights), len(heights[0])
        directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]
        res = []
        pacific, atlantic = set(), set()

        # bfs
        def bfs(visited):
            q = deque(visited)

            while q:
                r, c = q.popleft()
                for dr, dc in directions:
                    nr, nc = r + dr, c + dc
                    if 0 <= nr < ROWS and 0 <= nc < COLS and (nr, nc) not in visited and heights[r][c] <= heights[nr][nc]:
                        q.append((nr, nc))
                        visited.add((nr, nc))

        # insert cells on the border
        pacific = {(r, 0) for r in range(ROWS)} | {(0, c) for c in range(COLS)}
        atlantic = {(r, COLS-1) for r in range(ROWS)} | {(ROWS-1, c) for c in range(COLS)}

        bfs(pacific) # check pacific ocean -> atlantic ocean
        bfs(atlantic) # check atlantic ocean -> pacific ocean

        return [[r, c] for r in range(ROWS) for c in range(COLS) if (r, c) in pacific and (r, c) in atlantic]
  • 패턴: BFS, Hash Map / Hash Set
  • 설명: 모든 물리적 경계에서 BFS를 수행하여 오염 가능한 위치를 확장하고, 두 해양에 도달하는 좌표를 교집합으로 찾는 방식이다. 경로 확장은 인접한 높이가 비내림 조건을 만족하는 상태로 진행된다.

📊 시간/공간 복잡도 분석

복잡도
Time O(R * C)
Space O(R * C)

피드백: 각 바다에서 시작점 경계에서부터 높이가 비감소하는 방향으로 확산하여 도달 가능 좌표 집합을 만든다. 두 BFS의 합집합에서 교집합을 구하면 결과를 얻는다.

개선 제안: 현재 구현은 명확하고 충분하지만, 결과 저장을 boolean 배열로 두고 교집합 여부를 최종 판단하는 방식을 통해 약간의 상수시간을 줄일 수 있다.

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

@njngwn
njngwn merged commit a5ffc8f into DaleStudy:main Aug 22, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Solving to Completed in 리트코드 스터디 8기 Aug 22, 2026
@njngwn
njngwn deleted the week09 branch August 22, 2026 14:35
@DaleSeo

DaleSeo commented Aug 23, 2026

Copy link
Copy Markdown
Member

@njngwn 님, 다음 PR부터는 주차 설정이 누락되지 않도록 주의 부탁드리겠습니다. 본 PR은 제가 설정해드릴께요 :)

2026-08-23 at 10 18 51

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