Skip to content

[yuseok89] WEEK 09 Solutions - #2824

Open
yuseok89 wants to merge 6 commits into
DaleStudy:mainfrom
yuseok89:main
Open

[yuseok89] WEEK 09 Solutions#2824
yuseok89 wants to merge 6 commits into
DaleStudy:mainfrom
yuseok89:main

Conversation

@yuseok89

@yuseok89 yuseok89 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

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

  • Projects์˜ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ(โ–ผ)์„ ๋ˆŒ๋Ÿฌ ํ™•์žฅํ•œ ๋’ค, Week๋ฅผ ํ˜„์žฌ ์ฃผ์ฐจ๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”.
  • ๋ฌธ์ œ๋ฅผ ๋ชจ๋‘ ํ‘ธ์‹œ๋ฉด ํ”„๋กœ์ ํŠธ์—์„œ Status๋ฅผ In 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.

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

linked-list-cycle/yuseok89.py
# TC: O(N)
# SC: O(1)
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        if not head or not head.next:
            return False

        slow, fast = head, head.next
        while slow != fast:
            if not fast or not fast.next:
                return False

            slow, fast = slow.next, fast.next.next

        return True
  • ํŒจํ„ด: Two Pointers, Fast & Slow Pointers
  • ์„ค๋ช…: ํ•ด๋‹น ์ฝ”๋“œ๋Š” ๋А๋ฆฐ ํฌ์ธํ„ฐ์™€ ๋น ๋ฅธ ํฌ์ธํ„ฐ๋ฅผ ์ด์šฉํ•ด ์ˆœํ™˜ ์—ฌ๋ถ€๋ฅผ ํŒ๋ณ„ํ•˜๋Š” ์ „ํ˜•์ ์ธ Fast & Slow Pointers ํŒจํ„ด์ด๋‹ค. ๋‘ ํฌ์ธํ„ฐ์˜ ์†๋„ ์ฐจ์ด๋ฅผ ์ด์šฉํ•ด ์‚ฌ์ดํด ์กด์žฌ ์—ฌ๋ถ€๋ฅผ O(N) ์‹œ๊ฐ„, O(1) ๊ณต๊ฐ„์œผ๋กœ ํŒ๋‹จํ•œ๋‹ค.

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

๋ณต์žก๋„
Time O(n)
Space O(1)

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

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

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

@dalestudy

dalestudy Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

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

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

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
linked-list-cycle Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•
maximum-product-subarray Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
minimum-window-substring Hard โœ… ์˜๋„ํ•œ ์œ ํ˜•
pacific-atlantic-water-flow Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
sum-of-two-integers Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•

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

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

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

์นดํ…Œ๊ณ ๋ฆฌ ์ง„ํ–‰๋„ ์™„๋ฃŒ
Dynamic Programming โ– โ– โ– โ– โ– โ– โ–ก 9 / 11 (Easy 1, Medium 8)
Array โ– โ– โ– โ– โ– โ– โ–ก 8 / 10 (Medium 5, Easy 3)
Matrix โ– โ– โ– โ– โ– โ–กโ–ก 3 / 4 (Medium 3)
String โ– โ– โ– โ– โ– โ–กโ–ก 7 / 10 (Medium 4, Easy 3)
Binary โ– โ– โ– โ–กโ–กโ–กโ–ก 2 / 5 (Easy 2)
Graph โ– โ– โ– โ–กโ–กโ–กโ–ก 3 / 8 (Medium 3)
Linked List โ– โ– โ–กโ–กโ–กโ–กโ–ก 2 / 6 (Easy 2)
Heap โ– โ– โ–กโ–กโ–กโ–กโ–ก 1 / 3 (Medium 1)
Tree โ– โ– โ–กโ–กโ–กโ–กโ–ก 4 / 14 (Medium 3, Easy 1)
Interval โ–กโ–กโ–กโ–กโ–กโ–กโ–ก 0 / 5 โ† ์•„์ง ์‹œ์ž‘ ์•ˆ ํ•จ

๐Ÿค– ์ด ๋Œ“๊ธ€์€ GitHub App์„ ํ†ตํ•ด ์ž๋™์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿ”ข API ์‚ฌ์šฉ๋Ÿ‰ (gpt-5-nano)
์š”์ฒญ ์ž…๋ ฅ ํ† ํฐ ์ถœ๋ ฅ ํ† ํฐ ํ•ฉ๊ณ„ ๋น„์šฉ
1 340 50 390 $0.000037
2 340 53 393 $0.000038
3 2,029 204 2,233 $0.000183
ํ•ฉ๊ณ„ 2,709 307 3,016 $0.000258

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.

์กฐ๊ฑด๋ฌธ ๋ถ€๋ถ„์— ๊ฐ™์€์ง€ ๋น„๊ต๋ฅผ ํ•˜๋Š”๊ฒƒ๋„ ๊ฝค ๊ดœ์ฐฎ์€ ์•„์ด๋””์–ด์‹œ๋„ค์š”!
๋‹ค๋งŒ ์•„์ฃผ ๊ฐœ์ธ์ ์ธ ์˜๊ฒฌ์ธ๋ฐ, slow์™€ fast๋ฅผ ๋น„๊ตํ•˜๋Š”๊ฒƒ์€ ์ฐธ์กฐ๋ฅผ ๋น„๊ตํ•˜๋Š”๊ฑฐ๋ผ is๋ฅผ ์“ฐ๋Š”๊ฒŒ ๋” ๋‚ซ์ง€ ์•Š์„๊นŒ? ํ•˜๋Š” ์ƒ๊ฐ์ด ์žˆ์—ˆ์–ด์š”
์ข‹์€ ์ฝ”๋“œ ๋ณด๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

๋” ๋ช…ํ™•ํ•ด์ง€๊ฒ ๋„ค์š”.
๋ฐ˜์˜ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค !

@DaleSeo
DaleSeo self-requested a review August 20, 2026 03:15

@DaleSeo DaleSeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Comment thread linked-list-cycle/yuseok89.py Outdated
Comment on lines +11 to +12
if not head or not head.next:
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

๋…ธ๋“œ๊ฐ€ ํ•˜๋‚˜๋ฟ์ด๊ณ  ์ˆœํ™˜์ด ์—†๋Š” ์ž…๋ ฅ์ด๋ผ๋ฉด fast๊ฐ€ None์œผ๋กœ ์‹œ์ž‘ํ•˜๋ฏ€๋กœ, ๋ฐ˜๋ณต๋ฌธ ์•ˆ์˜ if not fast ๊ฐ€ ๊ณง๋ฐ”๋กœ False๋ฅผ ๋ฐ˜ํ™˜ํ•ด ์ค„ํ…๋ฐ์š”. ๊ทธ๋ ‡๋‹ค๋ฉด ์—ฌ๊ธฐ์„œ not head.next๊นŒ์ง€ ํ™•์ธํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–ค ๊ฒฝ์šฐ๋ฅผ ๋Œ€์‘ํ•˜๊ธฐ ์œ„ํ•œ ๋ชฉ์ ์ธ๊ฐ€์š”?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

์กฐ๊ธˆ ๊ณผํ•˜๊ฒŒ ์ƒ๊ฐํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๋ง์”€ ํ•˜์‹ ๋Œ€๋กœ, not head ๋งŒ์œผ๋กœ ์ถฉ๋ถ„ํ•ฉ๋‹ˆ๋‹ค.
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค !

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/yuseok89.py
# TC: O(N)
# SC: O(1)
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        if not head:
            return False

        slow, fast = head, head.next
        while slow is not fast:
            if not fast or not fast.next:
                return False

            slow, fast = slow.next, fast.next.next

        return True
  • ํŒจํ„ด: Fast & Slow Pointers
  • ์„ค๋ช…: ํ•ด๋‹น ์ฝ”๋“œ๋Š” ํ•œ ๋…ธ๋“œ๋Š” ํ•œ ์นธ, ๋‹ค๋ฅธ ๋…ธ๋“œ๋Š” ๋‘ ์นธ์”ฉ ์ง„ํ–‰ํ•˜๋Š” ๋‘ ํฌ์ธํ„ฐ๋ฅผ ์ด์šฉํ•ด ์ˆœํ™˜ ์—ฌ๋ถ€๋ฅผ ๊ฒ€์‚ฌํ•˜๋ฏ€๋กœ Fast & Slow Pointers ํŒจํ„ด์— ์†ํ•ฉ๋‹ˆ๋‹ค. ์‚ฌ์ดํด ์กด์žฌ ์—ฌ๋ถ€๋ฅผ 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.

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

maximum-product-subarray/yuseok89.py
# TC: O(N)
# SC: O(1)
class Solution:
    def maxProduct(self, nums: List[int]) -> int:

        ans = nums[0]
        max_val, min_val = 1, 1

        for num in nums:
            temp = max_val * num
            max_val = max(temp, min_val * num, num)
            min_val = min(temp, min_val * num, num)

            ans = max(ans, max_val)

        return ans
  • ํŒจํ„ด: Dynamic Programming, Two Pointers, Greedy
  • ์„ค๋ช…: ์—ฐ์† ๋ถ€๋ถ„ ๋ฐฐ์—ด์˜ ๊ณฑ์˜ ์ตœ๋Œ€๊ฐ’์„ ์œ ์ง€ํ•˜๋ฉฐ ํ˜„์žฌ ๊ตฌ๊ฐ„์˜ ์ตœ๋Œ“๊ฐ’๊ณผ ์ตœ์†Ÿ๊ฐ’์„ ๊ฐฑ์‹ ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ, ์—ฐ์† ๊ณฑ์˜ ๋ถ€ํ˜ธ ๋ณ€ํ™”์— ๋Œ€์‘ํ•˜๋Š” DP/์ƒํƒœ ์œ ์ง€ ํŒจํ„ด์œผ๋กœ ํ’€์ด๋œ๋‹ค. ๋˜ํ•œ ํ•œ ๋ฒˆ์˜ ์ˆœํšŒ๋กœ ํ•ด๊ฒฐํ•˜๋ฏ€๋กœ Sliding Window์— ๋น„์Šทํ•œ ํ๋ฆ„์ด ์žˆ์ง€๋งŒ ํ•ต์‹ฌ์€ ๋ถ€๋ถ„ ์ตœ๋Œ“๊ฐ’๊ณผ ์ตœ์†Ÿ๊ฐ’์˜ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๋™์  ๊ฒฐ์ •์ด๋‹ค.

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

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
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.

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

minimum-window-substring/yuseok89.py
# TC: O(N)
# SC: O(N)
class Solution:
    def minWindow(self, s: str, t: str) -> str:

        len_s = len(s)
        len_t = len(t)

        min_len = len_s + 1
        ans_start_idx = -1
        total_cnt = 0

        t_cnt_dict = Counter(t)
        cnt_dict = defaultdict(int)

        l, r = 0, 0

        while r < len_s:

            r_c = s[r]

            if cnt_dict[r_c] < t_cnt_dict.get(r_c, 0):
                total_cnt += 1

            cnt_dict[r_c] += 1
            r += 1

            while total_cnt == len_t:
                if min_len > r - l:
                    min_len = r - l
                    ans_start_idx = l

                l_c = s[l]

                if cnt_dict[l_c] <= t_cnt_dict[l_c]:
                    total_cnt -= 1

                cnt_dict[l_c] -= 1
                l += 1

        if ans_start_idx == -1:
            return ''

        return s[ans_start_idx:ans_start_idx + min_len]
  • ํŒจํ„ด: Sliding Window, Hash Map / Hash Set, Two Pointers
  • ์„ค๋ช…: ๋‘ ํฌ์ธํ„ฐ(l, r)๋กœ ์ฐฝ์„ ํ™•์žฅํ•˜๊ณ  ์ถ•์†Œํ•˜๋ฉด์„œ ํ•„์š”ํ•œ ๋ฌธ์ž ๊ฐœ์ˆ˜๋ฅผ ํ•ด์‹œ๋งต์œผ๋กœ ๊ด€๋ฆฌํ•˜๋Š” ํ‘œ์ค€ Sliding Window ํŒจํ„ด์œผ๋กœ ํ’€์ดํ•ฉ๋‹ˆ๋‹ค. ํ•ด์‹œ ๋งต์„ ์‚ฌ์šฉํ•ด ๋ฌธ์ž์˜ ๋นˆ๋„์ˆ˜๋ฅผ ์ถ”์ ํ•˜๊ณ  ์ตœ์†Œ ์ฐฝ์„ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค.

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

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(N) O( s
Space O(N) O( alphabet

ํ”ผ๋“œ๋ฐฑ: ์šฉ๋„์— ๋งž๋Š” ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ + ์นด์šดํŠธ ๋งคํ•‘์œผ๋กœ ์„ ํ˜• ์‹œ๊ฐ„ ๋ณต์žก๋„๋ฅผ ์–ป๋Š”๋‹ค.

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

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/yuseok89.py
# TC: O(N*M)
# SC: O(N*M)
class Solution:
    def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:

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

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

        def dfs(row, col, check):
            check[row][col] = True

            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 not check[new_row][new_col] and heights[row][col] <= heights[new_row][new_col]:
                    dfs(new_row, new_col, check)

        pac_check = [[False for _ in range(m)] for _ in range(n)]
        atl_check = [[False for _ in range(m)] for _ in range(n)]

        for row in range(1, n):
            dfs(row, 0, pac_check)

        for col in range(m):
            dfs(0, col, pac_check)

        for row in range(n - 1):
            dfs(row, m - 1, atl_check)

        for col in range(m):
            dfs(n - 1, col, atl_check)

        ans = []

        for row in range(n):
            for col in range(m):
                if pac_check[row][col] and atl_check[row][col]:
                    ans.append([row, col])

        return ans
  • ํŒจํ„ด: Depth-First Search, Binary Search
  • ์„ค๋ช…: ์œ ํ–ฅ ํ๋ฆ„ ๋Œ€์‹  ๋‘ ํ•ด๋ฐœ์˜ ๊ฒฝ๊ณ„๋ถ€ํ„ฐ DFS๋กœ ํผ์ ธ๋‚˜๊ฐ€๋ฉฐ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” ์œ„์น˜๋ฅผ ์ฐพ๋Š” ๊ตฌ์กฐ๋กœ, ๋‘ ๋ฐ”๋‹ค์—์„œ ๋„๋‹ฌ ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด DFS๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํŒจํ„ด์€ DFS์— ํ•ด๋‹นํ•˜๋ฉฐ, ์ด ๋ฌธ์ œ์˜ ํ•ต์‹ฌ์€ ๋‘ ๋ฐฉํ–ฅ์œผ๋กœ์˜ ํƒ์ƒ‰์„ ํ†ตํ•œ ๊ต์ง‘ํ•ฉ ํ™•์ธ์ž…๋‹ˆ๋‹ค.

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

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(N*M) O(nm) โŒ
Space O(N*M) O(nm) โŒ

ํ”ผ๋“œ๋ฐฑ: ๊ฐ ์…€์— ๋Œ€ํ•ด ๋‘ ๋ฐฉํ–ฅ์œผ๋กœ ๋„๋‹ฌ ๊ฐ€๋Šฅ ์—ฌ๋ถ€๋ฅผ ๊ธฐ๋กํ•˜๊ณ , ์‹œ์ž‘์ ์—์„œ ์ธ์ ‘ํ•œ ์…€๋กœ์˜ ํ๋ฆ„ ์กฐ๊ฑด์„ ์žฌ๊ท€์ ์œผ๋กœ ํ™•์žฅํ•œ๋‹ค.

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

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.

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

sum-of-two-integers/yuseok89.py
# TC: O(12)
# SC: O(1)
class Solution:
    def getSum(self, a: int, b: int) -> int:
        MASK = 0b111111111111

        a = a & MASK
        b = b & MASK

        while b != 0:
            c = (a & b) << 1
            a = a ^ b
            b = c & MASK

        if a > (MASK >> 1):
            a = ~(a ^ MASK)

        return a
  • ํŒจํ„ด: Bit Manipulation, Greedy
  • ์„ค๋ช…: ๋‘ ์ •์ˆ˜์˜ ํ•ฉ์„ ๋น„ํŠธ ์—ฐ์‚ฐ์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ, ๋น„ํŠธ ์—ฐ์‚ฐ๊ณผ ๋งˆ์Šคํฌ๋ฅผ ์ด์šฉํ•ด ํ•ฉ์„ ๊ตฌํ•˜๋Š” ์ ์—์„œ Bit Manipulation ํŒจํ„ด์— ์†ํ•ฉ๋‹ˆ๋‹ค. ์ถ”๊ฐ€์ ์œผ๋กœ ์ตœ์ ํ™”๋œ ์ƒ์ˆ˜ ๊ณต๊ฐ„ ์‚ฌ์šฉ์€ ๋ฌธ์ œ ํ•ด๊ฒฐ์˜ ์ผ๋ฐ˜์  ํŠน์ง•์œผ๋กœ ๋ณด์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

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

์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(12) O(1) โŒ
Space O(1) O(1) โœ…

ํ”ผ๋“œ๋ฐฑ: ๋น„ํŠธ ์—ฐ์‚ฐ์œผ๋กœ ๋ฌธ์ž์—ด์  ๊ตฌํ˜„ ์—†์ด ๋ง์…ˆ์„ ๊ตฌํ˜„ํ•œ๋‹ค.

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

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.

3 participants