Skip to content

[okyungjin] WEEK 04 Solutions#2743

Open
okyungjin wants to merge 2 commits into
DaleStudy:mainfrom
okyungjin:main
Open

[okyungjin] WEEK 04 Solutions#2743
okyungjin wants to merge 2 commits into
DaleStudy:mainfrom
okyungjin:main

Conversation

@okyungjin

@okyungjin okyungjin commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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

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

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

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

Important

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

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

@dalestudy

dalestudy Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

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

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

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
merge-two-sorted-lists Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•

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

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

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

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

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

๐Ÿ”ข API ์‚ฌ์šฉ๋Ÿ‰ (gpt-5-nano)
์š”์ฒญ ์ž…๋ ฅ ํ† ํฐ ์ถœ๋ ฅ ํ† ํฐ ํ•ฉ๊ณ„ ๋น„์šฉ
1 1,200 37 1,237 $0.000075
2 1,196 46 1,242 $0.000078
ํ•ฉ๊ณ„ 2,396 83 2,479 $0.000153

@github-actions github-actions Bot added the py label Jul 13, 2026

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.

@DaleStudy ๊ฐœ์„  ์ œ์•ˆ: ๋” ๋‚˜์€ ๋ณ€์ˆ˜ ๋„ค์ด๋ฐ๊ณผ ์ฃผ์„ ์ •๋ฆฌ๋กœ ๊ฐ€๋…์„ฑ์„ ๋†’์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋Š” ์–ด๋–ค ๋ฐฉ์‹์„ ๋งํ•˜๋Š”๊ฑด์ง€ ์ œ์•ˆํ•ด์ฃผ๋ผ

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.

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

  • ํŒจํ„ด: Two Pointers, Linked List, Greedy, Dynamic Programming, Hash Map / Hash Set, Divide and Conquer, Backtracking, DFS, BFS, Heap / Priority Queue, Trie, Bit Manipulation, Monotonic Stack, Union Find, Binary Search
  • ์„ค๋ช…: ๋ฆฌ์ŠคํŠธ๋ฅผ ๋‘ ํฌ์ธํ„ฐ๋กœ ์ˆœํšŒํ•˜๋ฉฐ ์ •๋ ฌ๋œ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ณ‘ํ•ฉํ•˜๋Š” ํŒจํ„ด์œผ๋กœ, ๋‘ ๋…ธ๋“œ๋ฅผ ๋น„๊ตํ•ด ๋” ์ž‘์€ ๊ฐ’์„ ํ˜„์žฌ ๋…ธ๋“œ์— ์—ฐ๊ฒฐํ•˜๊ณ  ํฌ์ธํ„ฐ๋ฅผ ์ „์ง„์‹œํ‚ต๋‹ˆ๋‹ค. ์ถ”๊ฐ€ ๊ณต๊ฐ„ ์—†์ด ๊ธฐ์กด ๋…ธ๋“œ๋ฅผ ์žฌํ™œ์šฉํ•˜๋Š” ์ตœ์ ํ™”๊ฐ€ ํŠน์ง•์ž…๋‹ˆ๋‹ค.

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

โ„น๏ธ ์ด ํŒŒ์ผ์—๋Š” 2๊ฐ€์ง€ ํ’€์ด๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์–ด ๊ฐ๊ฐ ๋ถ„์„ํ•ฉ๋‹ˆ๋‹ค.

ํ’€์ด 1: Solution_01.mergeTwoLists โ€” Time: โœ… O(n + m) โ†’ O(n + m) / Space: โŒ O(n + m) โ†’ O(1)
์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(n + m) O(n + m) โœ…
Space O(n + m) O(1) โŒ

ํ”ผ๋“œ๋ฐฑ: ๋‘ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ๊ฐ ๋…ธ๋“œ๋ฅผ ์ƒˆ๋กœ ๋งŒ๋“ค์ง€ ์•Š๊ณ  ๊ธฐ์กด ๋…ธ๋“œ๋ฅผ ์—ฐ๊ฒฐํ•ด ๊ณต๊ฐ„์„ ์ƒ์ˆ˜๋กœ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

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

ํ’€์ด 2: Solution.mergeTwoLists โ€” Time: โœ… O(n + m) โ†’ O(n + m) / Space: โœ… O(1) โ†’ O(1)
์œ ์ € ๋ถ„์„ ์‹ค์ œ ๋ถ„์„ ๊ฒฐ๊ณผ
Time O(n + m) O(n + m) โœ…
Space O(1) O(1) โœ…

ํ”ผ๋“œ๋ฐฑ: ๋…ธ๋“œ๋ฅผ ์ƒˆ๋กœ ์ƒ์„ฑํ•˜์ง€ ์•Š๊ณ  ๊ธฐ์กด ListNode๋ฅผ ์—ฐ๊ฒฐํ•ด ๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ๊ฐœ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค.

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

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.

@DaleStudy ํ’€์ด1 ๊ณต๊ฐ„ ๋ณต์žก๋„ ์„ค๋ช…ํ•ด์ฃผ๋ผ. ํ’€์ด 1์—์„œ ์ƒˆ๋กœ์šด ๋…ธ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋น„์šฉ์„ ์ตœ์ ํ™”ํ•˜๋ ค๊ณ  ํ’€์ด2๋กœ ๋ณ€๊ฒฝํ•œ๊ฑฐ๊ฑฐ๋“ . ๋‘˜๋‹ค 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.

์š”์•ฝ ๋‹ต๋ณ€

  • ํ’€์ด 1์€ ์ƒˆ๋กœ์šด ๋…ธ๋“œ(ListNode)๋ฅผ ๋งค๋ฒˆ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ถ”๊ฐ€ ๊ณต๊ฐ„์€ ์ƒˆ ๋…ธ๋“œ๋“ค์— ์˜ํ•ด O(n+m) ์ž…๋‹ˆ๋‹ค. (์—ฌ๊ธฐ์„œ๋Š” ๋‘ ๋ฆฌ์ŠคํŠธ์˜ ๊ธธ์ด ํ•ฉ์— ๋น„๋ก€)
  • ํ’€์ด 2(๊ณต๊ฐ„ ๋ณต์žก๋„ O(1)์œผ๋กœ ๊ฐœ์„ )๋Š” ๊ธฐ์กด ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ๋ฅผ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ƒˆ ๋…ธ๋“œ๋ฅผ ๋งŒ๋“ค์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋”๋ฏธ ๋…ธ๋“œ ํ•˜๋‚˜(dummy)์™€ ํฌ์ธํ„ฐ๋“ค๋งŒ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์ถ”๊ฐ€ ๊ณต๊ฐ„์€ ์ƒ์ˆ˜ O(1) ์ž…๋‹ˆ๋‹ค.
  • ๊ฒฐ๋ก : ํ’€์ด 1์€ O(n+m) ๊ณต๊ฐ„, ํ’€์ด 2๋Š” O(1) ๊ณต๊ฐ„. ๋‘ ๋ฐฉ๋ฒ• ์ค‘์—์„œ ํ’€์ด 2๊ฐ€ ๊ณต๊ฐ„ ์ธก๋ฉด์—์„œ ์ตœ์ ํ™”๋œ ๋ฒ„์ „์ž…๋‹ˆ๋‹ค. ๋‹ค๋งŒ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” ๋‘˜ ๋‹ค O(n+m)๋กœ ๊ฐ™์Šต๋‹ˆ๋‹ค.

@okyungjin okyungjin Jul 13, 2026

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.

@DaleStudy ๊ทธ๋Ÿฌ๋ฉด #2743 (comment) ํ’€์ด 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 + m)์ž…๋‹ˆ๋‹ค. ์ด์œ ๋Š” ์ƒˆ๋กœ์šด ListNode๋ฅผ ๋งค๋ฒˆ ์ƒ์„ฑํ•˜๋ฏ€๋กœ ๋‘ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ๋ฅผ ํ•ฉ์นœ ๊ธธ์ด๋งŒํผ ์ถ”๊ฐ€ ๋…ธ๋“œ๊ฐ€ ํ•„์š”ํ•ด์ง€๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์ฆ‰, ์ถ”๊ฐ€๋œ ๋…ธ๋“œ ์ˆ˜๊ฐ€ n + m๊ฐœ๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•ฉ๋‹ˆ๋‹ค.

PR ์ฝ”๋“œ์˜ ๊ตฌํ˜„ ๊ด€์ ์—์„œ ๋ณด๋ฉด:

  • ์ดˆ๊ธฐ ๋ฒ„์ „(Solution_01)์€ ๋งค ๋ณ‘ํ•ฉ๋งˆ๋‹ค ์ƒˆ ๋…ธ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋ฏ€๋กœ ์ถ”๊ฐ€ ๊ณต๊ฐ„์ด O(n + m).
  • ๊ฐœ์„ ์•ˆ(Solution)์€ ์‹ค์ œ ๋…ธ๋“œ๋ฅผ ์žฌ์‚ฌ์šฉํ•˜๋ฏ€๋กœ ์ถ”๊ฐ€ ๊ณต๊ฐ„์€ O(1)๋กœ ์ค„์˜€์Šต๋‹ˆ๋‹ค.

๋”ฐ๋ผ์„œ "ํ’€์ด 1์—์„œ์˜ ์˜ˆ์ธก ๊ณต๊ฐ„ ๋ณต์žก๋„"๋Š” ๋งž๊ณ , ์‹ค์ œ๋กœ๋Š” ๊ฐœ์„ ๋œ ๋ฒ„์ „์—์„œ O(1)๋กœ ์ตœ์ ํ™”๋œ๋‹ค๊ณ  ๋ณด๋Š” ๊ฒŒ ์ •ํ™•ํ•ฉ๋‹ˆ๋‹ค. ํ•„์š”ํ•˜๋ฉด ๋‘ ๋ฒ„์ „์˜ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ๋Ÿ‰ ๋น„๊ต๋‚˜ ์‹œ๊ฐ„ ๋ณต์žก๋„๋„ ํ•จ๊ป˜ ์ •๋ฆฌํ•ด ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

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.

@DaleStudy ๊ทธ๋Ÿฌ๋ฉด โŒ ํ‘œ์‹œ ์—†์–ด์•ผ ํ•˜๋Š”๊ฑฐ ์•„๋‹Œ๊ฐ€ํ•ด์„œ! ์ € ๋ถ„์„ ํ‘œ๋ฅผ ๋‹ค์‹œ ๊ทธ๋ ค์ฃผ๋ผ

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.

์•„, ํ‘œ์—์„œ โŒ๊ฐ€ ์—†์–ด์•ผ ํ•œ๋‹ค๊ณ  ๋А๋ผ์‹  ๊ฑฐ์ฃ ? PR ์„ค๋ช…์˜ ์ฒดํฌ๋ฆฌ์ŠคํŠธ๋Š” ๋ฆฌ๋ทฐ์–ด๊ฐ€ ํ™•์ธ์šฉ์œผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ํฌ๋งท์ด๋ผ, ๋ณดํ†ต ๊ฐ ํ•ญ๋ชฉ์˜ ์ƒํƒœ๋ฅผ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด โœ”/x ํ‘œ๊ธฐ๊ฐ€ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ๋Š” ํ•„์š”์— ๋”ฐ๋ผ ํ‘œ๊ธฐ๋ฅผ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ ์ค‘ ์›ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ฐ”๊ฟ” ๋ณด์„ธ์š”:

  • ๋ชจ๋“  ํ•ญ๋ชฉ์— ์ฒดํฌ ํ‘œ์‹œ๋ฅผ ์ œ๊ฑฐ: ๊น”๋”ํ•œ ๋ชฉ๋ก์œผ๋กœ ๋‚จ๊น€
  • ๊ฐ ํ•ญ๋ชฉ์— ์ƒํƒœ๋ฅผ ํ…์ŠคํŠธ๋กœ๋งŒ ํ‘œํ˜„: ์˜ˆ) [์™„๋ฃŒ], [๋ฏธ์™„]
  • ๋˜๋Š” ๋ถˆํ•„์š”ํ•œ ์ฒดํฌ์นธ์„ ์ œ๊ฑฐํ•˜๊ณ  ํ•œ ์ค„ ์š”์•ฝ์œผ๋กœ๋งŒ ๋‚จ๊น€

์˜ˆ์‹œ (์ฒดํฌ๋ฐ•์Šค ์—†์ด ๊ฐ„๋‹จํ•œ ๋ชฉ๋ก):

์›ํ•˜์‹œ๋Š” ํ‘œ ํ˜•์‹์ด๋‚˜ ํ‘œ๊ธฐ ๋ฐฉ์‹(๋งˆํฌ๋‹ค์šด ์—ฌ๋ถ€, ํ•œ ์ค„ ์š”์•ฝ ๋“ฑ)์„ ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๊ทธ์— ๋งž์ถฐ ๋‹ค์‹œ ๊ทธ๋ ค๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.

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.

@DaleStudy ์ด ํŒŒ์ผ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ๋ถ„์„

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.

๋‹ค์Œ ๋‘ ๊ตฌํ˜„์˜ ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„ ์ฐจ์ด์™€ ๊ณตํ†ต์ :

  • Solution_01

    • ์‹œ๊ฐ„ ๋ณต์žก๋„: O(n + m) โ€” list1๊ณผ list2์˜ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๊ฐ๊ฐ ํ•œ ๋ฒˆ์”ฉ ํ™•์ธํ•˜๋ฉฐ ๋ณ‘ํ•ฉ.
    • ๊ณต๊ฐ„ ๋ณต์žก๋„: O(n + m) โ€” ์ƒˆ๋กœ์šด ListNode๋ฅผ ๋งค ๋ฐ˜๋ณต๋งˆ๋‹ค ์ƒ์„ฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋‘ ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ ์ˆ˜๋งŒํผ ์ถ”๊ฐ€ ๋…ธ๋“œ๊ฐ€ ๋งŒ๋“ค์–ด์ง.
  • Solution

    • ์‹œ๊ฐ„ ๋ณต์žก๋„: O(n + m) โ€” ๋™์ผํ•˜๊ฒŒ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ํ•œ ๋ฒˆ์”ฉ ์ˆœํšŒํ•˜๋ฉฐ ๋ณ‘ํ•ฉ.
    • ๊ณต๊ฐ„ ๋ณต์žก๋„: O(1) โ€” ์ƒˆ ๋…ธ๋“œ ์ƒ์„ฑ ์—†์ด ๊ธฐ์กด ๋ฆฌ์ŠคํŠธ์˜ ๋…ธ๋“œ๋ฅผ ์žฌ์‚ฌ์šฉ. ๋”๋ธ” ํฌ์ธํ„ฐ ๋ฐฉ์‹์˜ ์ƒ์ˆ˜ ๊ณต๊ฐ„๋งŒ ํ•„์š”.

์ฃผ์˜์ 

  • ๋‘ ๊ตฌํ˜„์€ dummy๋ฅผ ์‚ฌ์šฉํ•ด ๋ณ‘ํ•ฉ head๋ฅผ ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌํ•œ๋‹ค.
  • Solution_01์€ ์ƒˆ ๋…ธ๋“œ๋ฅผ ๋งŒ๋“ค์–ด ๊ณต๊ฐ„์ด ์ถ”๊ฐ€๋˜๊ณ , Solution์€ ๊ธฐ์กด ๋…ธ๋“œ๋ฅผ ์—ฐ๊ฒฐ๋งŒ ํ•˜๋ฏ€๋กœ ๋ฉ”๋ชจ๋ฆฌ ํšจ์œจ์ด ๋” ์ข‹๋‹ค.

@ICE0208
ICE0208 self-requested a review July 14, 2026 04:20

# ๊ฐ’์„ ๋น„๊ตํ•ด์„œ ์ž‘์€ ๊ฐ’์„ next ๋…ธ๋“œ์— ์ถ”๊ฐ€ํ•œ๋‹ค.
if list1.val <= list2.val:
node.next = ListNode(list1.val)

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.

์ด ๋ถ€๋ถ„์—์„œ ListNode(list1.val)๋กœ ๋งค๋ฒˆ ์ƒˆ ๋…ธ๋“œ๋ฅผ ์ƒ์„ฑํ•˜์‹œ๋Š”๋ฐ, ๊ธฐ์กด ๋…ธ๋“œ๋ฅผ ๊ทธ๋Œ€๋กœ ์—ฐ๊ฒฐ(node.next = list1)ํ•˜๋ฉด ์ƒˆ ๋…ธ๋“œ๋ฅผ ์•ˆ ๋งŒ๋“ค์–ด๋„ ๋ผ์„œ ๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ 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