Skip to content

[dolphinflow86] WEEK 07 Solutions - #2799

Open
dolphinflow86 wants to merge 3 commits into
DaleStudy:mainfrom
dolphinflow86:main
Open

[dolphinflow86] WEEK 07 Solutions#2799
dolphinflow86 wants to merge 3 commits into
DaleStudy:mainfrom
dolphinflow86:main

Conversation

@dolphinflow86

@dolphinflow86 dolphinflow86 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

๋‹ต์•ˆ ์ œ์ถœ ๋ฌธ์ œ

  • reverse-linked-list
  • longest-substring-without-repeating-characters
  • number-of-islands
  • unique-paths
  • set-matrix-zeroes

์ž‘์„ฑ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In Review๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ์ฝ”๋“œ ๊ฒ€ํ† ์ž 1๋ถ„ ์ด์ƒ์œผ๋กœ๋ถ€ํ„ฐ ์Šน์ธ์„ ๋ฐ›์œผ์…จ๋‹ค๋ฉด PR์„ ๋ณ‘ํ•ฉํ•ด์ฃผ์„ธ์š”.

๊ฒ€ํ† ์ž ์ฒดํฌ ๋ฆฌ์ŠคํŠธ

Important

๋ณธ์ธ ๋‹ต์•ˆ ์ œ์ถœ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ ๋ถ„ PR ํ•˜๋‚˜ ์ด์ƒ์„ ๋ฐ˜๋“œ์‹œ ๊ฒ€ํ† ๋ฅผ ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค!

  • ๋ฐ”๋กœ ์ด์ „์— ์˜ฌ๋ผ์˜จ PR์— ๋ณธ์ธ์„ ์ฝ”๋“œ ๋ฆฌ๋ทฐ์–ด๋กœ ์ถ”๊ฐ€ํ•ด์ฃผ์„ธ์š”.
  • ๋ณธ์ธ์ด ๊ฒ€ํ† ํ•ด์•ผํ•˜๋Š” PR์˜ ๋‹ต์•ˆ ์ฝ”๋“œ์— ํ”ผ๋“œ๋ฐฑ์„ ์ฃผ์„ธ์š”.
  • ํ† ์š”์ผ ์ „๊นŒ์ง€ PR์„ ๋ณ‘ํ•ฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์Šน์ธํ•ด์ฃผ์„ธ์š”.

@dolphinflow86 dolphinflow86 changed the title [dolphinflow86] WEEK 07 Solutions- #2798 [dolphinflow86] WEEK 07 Solutions Aug 6, 2026
@github-actions github-actions Bot added the py label 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.

๐Ÿท๏ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด ๋ถ„์„

longest-substring-without-repeating-characters/dolphinflow86.py
# N is the length of s.
# TC: O(N) - each character is added and removed at most once
# SC: O(N) - stores the characters in the current window
class Solution:

    def lengthOfLongestSubstring(self, s: str) -> int:
        chars = set()
        left = 0
        longest = 0

        for right, char in enumerate(s):
            while char in chars:
                chars.remove(s[left])
                left += 1

            chars.add(char)
            longest = max(longest, right - left + 1)

        return longest
  • ํŒจํ„ด: Sliding Window, Hash Map / Hash Set
  • ์„ค๋ช…: ๋ฌธ์ž์—ด์—์„œ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ์œ„ํ•ด ์ฐฝ์„ ์›€์ง์ด๋ฉฐ(left, right) ํ˜„์žฌ ์œˆ๋„์šฐ์˜ ๋ฌธ์ž๋“ค์„ ์ง‘ํ•ฉ์— ์ €์žฅํ•˜๊ณ , ์ค‘๋ณต ์‹œ ์™ผ์ชฝ ํฌ์ธํ„ฐ๋ฅผ ์ด๋™์‹œํ‚ค๋Š” ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ ํŒจํ„ด์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํ•ด์‹œ ์„ธํŠธ๋ฅผ ์ด์šฉํ•ด ๋ฌธ์ž ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
Space O(min(n, m))

ํ”ผ๋“œ๋ฐฑ: ํ•ด๋‹น ๊ตฌํ˜„์€ ๋ชจ๋“  ๋ฌธ์ž๋ฅผ ํ•œ ๋ฒˆ์”ฉ ์ถ”๊ฐ€/์ œ๊ฑฐํ•˜๋ฉฐ ์œˆ๋„์šฐ๋ฅผ ์ด๋™์‹œํ‚ค๋ฏ€๋กœ ์„ ํ˜• ์‹œ๊ฐ„๊ณผ ์ฐฝ ํฌ๊ธฐ์— ๋น„๋ก€ํ•œ ์ถ”๊ฐ€ ๊ณต๊ฐ„์„ ์‚ฌ์šฉํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์ด ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

๐Ÿ’ก ํ’€์ด์— ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ฃผ์„์œผ๋กœ ๋‚จ๊ฒจ๋ณด์„ธ์š”!

@dalestudy

dalestudy Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

๐Ÿ“Š dolphinflow86 ๋‹˜์˜ ํ•™์Šต ํ˜„ํ™ฉ

์ด๋ฒˆ ์ฃผ ์ œ์ถœ ๋ฌธ์ œ

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
longest-substring-without-repeating-characters Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
number-of-islands Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
reverse-linked-list Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•

๋ˆ„์  ํ•™์Šต ์š”์•ฝ

  • ํ’€์ดํ•œ ๋ฌธ์ œ: 30 / 75๊ฐœ
  • ์ด๋ฒˆ ์ฃผ ์œ ํ˜• ์ผ์น˜์œจ: 100% (3๋ฌธ์ œ ์ค‘ 3๋ฌธ์ œ ์ผ์น˜)

๋ฌธ์ œ ํ’€์ด ํ˜„ํ™ฉ

์นดํ…Œ๊ณ ๋ฆฌ ์ง„ํ–‰๋„ ์™„๋ฃŒ
Array โ– โ– โ– โ– โ– โ– โ–ก 8 / 10 (Medium 5, Easy 3)
Dynamic Programming โ– โ– โ– โ– โ–กโ–กโ–ก 7 / 11 (Easy 1, Medium 6)
Matrix โ– โ– โ– โ– โ–กโ–กโ–ก 2 / 4 (Medium 2)
String โ– โ– โ– โ– โ–กโ–กโ–ก 5 / 10 (Medium 2, 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 1,090 145 1,235 $0.000113

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/dolphinflow86.py
# R is the number of rows, and C is the number of columns.
# TC: O(R * C) - visits each cell at most once
# SC: O(R * C) - uses the recursion stack in the worst case
class Solution:

    def numIslands(self, grid: List[List[str]]) -> int:
        rows = len(grid)
        cols = len(grid[0])

        def dfs(row, col):
            if (
                row < 0
                or row >= rows
                or col < 0
                or col >= cols
                or grid[row][col] != "1"
            ):
                return

            grid[row][col] = "0"

            dfs(row - 1, col)
            dfs(row + 1, col)
            dfs(row, col - 1)
            dfs(row, col + 1)

        islands = 0

        for row in range(rows):
            for col in range(cols):
                if grid[row][col] == "1":
                    islands += 1
                    dfs(row, col)

        return islands
  • ํŒจํ„ด: Depth-First Search, Backtracking
  • ์„ค๋ช…: ๊ทธ๋ฆฌ๋“œ์—์„œ 1๋กœ ์—ฐ๊ฒฐ๋œ ์˜์—ญ์„ DFS๋กœ ํƒ์ƒ‰ํ•˜๋ฉฐ ๋ฐฉ๋ฌธํ•œ ๋…ธ๋“œ๋ฅผ 0์œผ๋กœ ๋ฐ”๊ฟ” ์—ฐ๊ฒฐ ์š”์†Œ(์„ฌ)์˜ ๊ฐœ์ˆ˜๋ฅผ ์…ˆ. ์žฌ๊ท€๋ฅผ ์ด์šฉํ•œ ๊นŠ์€ ํƒ์ƒ‰์ด ํ•ต์‹ฌ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(R * C) O(rows * cols) โŒ
Space O(R * C) O(rows * cols) โŒ

ํ”ผ๋“œ๋ฐฑ: ๊ทธ๋ฆฌ๋“œ์˜ ๊ฐ ์…€์„ ํ•œ ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๊ณ  ์ธ์ ‘ํ•œ '1'๋“ค์„ ์žฌ๊ท€์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ์žฌ๊ท€ ๊นŠ์ด๊ฐ€ ์ปค์งˆ ์ˆ˜ ์žˆ๋Š” ํ™˜๊ฒฝ์—์„œ๋Š” ์Šคํƒ ๊ธฐ๋ฐ˜ DFS๋‚˜ BFS๋กœ ์Šคํƒ ์‚ฌ์šฉ์„ ๋ช…์‹œํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•˜๋‹ค.

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/dolphinflow86.py
# TC: O(N) - visits each node exactly once
# SC: O(1) - reverses the links in place
class Solution:

    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        prev = None
        current = head

        while current:
            next_node = current.next
            current.next = prev
            prev = current
            current = next_node

        return prev
  • ํŒจํ„ด: Two Pointers, Linked List
  • ์„ค๋ช…: ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋Š” ๋‹จ์ˆœํžˆ ํฌ์ธํ„ฐ ๋‘ ๊ฐœ๋ฅผ ์‚ฌ์šฉํ•ด ๋งํฌ๋“œ ๋ฆฌ์ŠคํŠธ์˜ ๋ฐฉํ–ฅ์„ ๋ฐ˜๋Œ€๋กœ ๋ฐ”๊พธ๋Š” ๊ณผ์ •์œผ๋กœ, ๋…ธ๋“œ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ๋…ธ๋“œ์˜ ๋งํฌ๋ฅผ ๋’ค์ง‘๋Š” ๋ฐ ๋‘ ํฌ์ธํ„ฐ๋ฅผ ํ™œ์šฉํ•˜๋Š” ํŒจํ„ด์ด ํ•ต์‹ฌ์ž…๋‹ˆ๋‹ค. ์‹œ๊ฐ„ ๋ณต์žก๋„ O(N), ๊ณต๊ฐ„ ๋ณต์žก๋„ O(1)๋กœ ๊ตฌํ˜„๋ฉ๋‹ˆ๋‹ค.

๐Ÿ“Š ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

๋ณต์žก๋„
Time O(n)
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.

์ œ ๊ฐœ์ธ์ ์ธ ์ƒ๊ฐ์—๋Š”์š”! head๋ฅผ ๋ฆฌํ„ด ํ˜น์€ ์–ด๋””์—๋„ ์“ฐ์ง€ ์•Š์œผ๋‹ˆ current๋ฅผ ์“ฐ์‹œ๋Š” ๋ถ€๋ถ„ ๊ทธ๋Œ€๋กœ head๋ฅผ ์“ฐ์…”๋„ ๋˜์ง€ ์•Š์„๊นŒ?
ํ•˜๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์š”!

๊ทธ๋ฆฌ๊ณ  ํŒŒ์ด์ฌ์˜ a, b = b, a์ฒ˜๋Ÿผ ์“ธ์ˆ˜ ์žˆ๋Š” ๋ฌธ๋ฒ•์„ ํ™œ์šฉํ•˜์‹œ๋ฉด while loop ์•ˆ์„ 1์ค„๋กœ ์ค„์ด์‹ค์ˆ˜๋„ ์žˆ๋‹ต๋‹ˆ๋‹ค!

@yuseok89
yuseok89 self-requested a review August 6, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants