Skip to content

[parkhojeong] WEEK 07 Solutions - #2795

Open
parkhojeong wants to merge 8 commits into
DaleStudy:mainfrom
parkhojeong:week7
Open

[parkhojeong] WEEK 07 Solutions#2795
parkhojeong wants to merge 8 commits into
DaleStudy:mainfrom
parkhojeong:week7

Conversation

@parkhojeong

@parkhojeong parkhojeong commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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

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

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

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

Important

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

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

@dalestudy

dalestudy Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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

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

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
longest-substring-without-repeating-characters Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
number-of-islands Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•
reverse-linked-list Easy โœ… ์˜๋„ํ•œ ์œ ํ˜•
set-matrix-zeroes Medium โš ๏ธ ์œ ํ˜• ๋ถˆ์ผ์น˜
unique-paths Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•

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

  • ํ’€์ดํ•œ ๋ฌธ์ œ: 30 / 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 โ– โ– โ– โ– โ–กโ–กโ–ก 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,990 222 2,212 $0.000188
2 1,889 212 2,101 $0.000179
3 1,891 203 2,094 $0.000176
ํ•ฉ๊ณ„ 5,770 637 6,407 $0.000543

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.

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

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

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

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

ํ”ผ๋“œ๋ฐฑ: ๋ฌธ์ž ์ธ๋ฑ์Šค ์ €์žฅ์†Œ๋ฅผ ์‚ฌ์šฉํ•ด ๊ฐ ๋ฌธ์ž ๋งˆ์ง€๋ง‰ ์œ„์น˜๋ฅผ ์ถ”์ ํ•˜๊ณ , ์ค‘๋ณต์ด ๋“ฑ์žฅํ•˜๋ฉด ์‹œ์ž‘ ์ธ๋ฑ์Šค๋ฅผ ๊ฐฑ์‹ ํ•œ๋‹ค.

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

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

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.

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

  • ํŒจํ„ด: Depth-First Search, Backtracking
  • ์„ค๋ช…: ์„ฌ์˜ ๋ฐฉ๋ฌธ ์—ฌ๋ถ€๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ํƒ์ƒ‰ํ•˜๋ฉฐ ์—ฐ๊ฒฐ๋œ '1'์„ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌํ•˜๋Š” DFS ํŒจํ„ด์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ๊ฐ ์„ฌ์˜ ์‹œ์ž‘์ ์—์„œ ์—ฐ๊ฒฐ๋œ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•ด์„œ ์นด์šดํŠธํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•ฉ๋‹ˆ๋‹ค.

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

๋ณต์žก๋„
Time O(rows * cols)
Space O(rows * cols)

ํ”ผ๋“œ๋ฐฑ: ๊ทธ๋ฆฌ๋“œ์˜ ๋ชจ๋“  ์›์†Œ๋ฅผ ํ•œ ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๊ณ , ์„ฌ์˜ ์—ฐ๊ฒฐ ์š”์†Œ๋ฅผ DFS๋กœ ํƒ์ƒ‰ํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ์žฌ๊ท€ ๊นŠ์ด๊ฐ€ ํฐ ์ž…๋ ฅ์— ๋Œ€๋น„ํ•ด ๋น„์žฌ๊ท€ 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.

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

  • ํŒจํ„ด: Two Pointers, Linked List
  • ์„ค๋ช…: ์ฃผ์–ด์ง„ ์ฝ”๋“œ๋Š” ๋‹จ์ผ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ๋’ค์ง‘๊ธฐ ์œ„ํ•ด ๋‘ ํฌ์ธํ„ฐ(prev, cur)๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ํ•œ ๋…ธ๋“œ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ์—ฐ๊ฒฐ ๋ฐฉํ–ฅ์„ ๋ฐ”๊ฟ” ๊ฐ€๋ฉฐ ์ง„ํ–‰ํ•˜๋Š” ๋Œ€ํ‘œ์  ํŒจํ„ด์ž…๋‹ˆ๋‹ค.

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

๋ณต์žก๋„
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.

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

  • ํŒจํ„ด: Depth-First Search, Greedy, Hash Map / Hash Set
  • ์„ค๋ช…: ์ฝ”๋“œ๊ฐ€ DFS๋กœ ๊ฐ ๋ฐฉํ–ฅ์œผ๋กœ ํƒ์ƒ‰ํ•˜๋ฉฐ 0์ธ ์œ„์น˜๋ฅผ ๋งˆ์ปค๋กœ ํ‘œ์‹œํ•œ ๋’ค, ๋งˆ์ง€๋ง‰์— ๋‹ค์‹œ 0์œผ๋กœ ๋ณต์›ํ•ฉ๋‹ˆ๋‹ค. ์ธ์ ‘ํ•œ 0์˜ ์œ„์น˜๋ฅผ ํ‘œ์‹œํ•˜๋Š” ๋ฐฉ์‹์€ ํƒ์ƒ‰ ํŒจํ„ด๊ณผ ํ”Œ๋ž˜๊ทธ ๋งˆํ‚น์˜ ์กฐํ•ฉ์œผ๋กœ ๋ณด์ด๋ฉฐ, ๊ฐ„๋‹จํ•œ ๋งˆ์ปค๋ฅผ ์‚ฌ์šฉํ•œ ํƒ์ƒ‰ ๊ธฐ๋ฒ•์ด ๋“œ๋Ÿฌ๋‚ฉ๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ๋‘ ๋‹จ๊ณ„๋กœ ๋‚˜๋ˆ  ์ œ๋กœ๋ฅผ ํ™•์‚ฐ์‹œํ‚ค๋Š” ๋ฐฉ์‹์œผ๋กœ in-place ํ•ด๊ฒฐ์„ ์‹œ๋„ํ–ˆ๋‹ค.

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

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

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.

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

  • ํŒจํ„ด: Dynamic Programming, Greedy, Hash Map / Hash Set
  • ์„ค๋ช…: ํŠน์ • ์นธ์˜ ๊ฒฝ๋กœ ์ˆ˜๋ฅผ ์œ„์ชฝ๊ณผ ์™ผ์ชฝ ์นธ์˜ ์ˆ˜์˜ ํ•ฉ์œผ๋กœ ๊ณ„์‚ฐํ•˜๋Š” DP ๋ฐฉ์‹์œผ๋กœ ํ•ด๋ฅผ ๊ตฌํ•ฉ๋‹ˆ๋‹ค. ๊ฒน์น˜๋Š” ๋ถ€๋ถ„ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ฉฐ ๊ทธ๋ฆฌ๋“œ ์ˆœํšŒ๋กœ ๊ฒฐ๊ณผ๋ฅผ ์ฑ„์›๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ์™ผ์ชฝ ์œ„์—์„œ ์˜ค๋ฅธ์ชฝ ์•„๋ž˜๋กœ ๊ฒฝ๋กœ์˜ ์ˆ˜๋ฅผ ๋ˆ„์  ํ•ฉ์œผ๋กœ ๊ตฌํ•œ๋‹ค.

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

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

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.

์ด๊ฑฐ ์žฌ๊ท€๋•Œ๋ฌธ์— ๊ณต๊ฐ„๋ณต์žก๋„ O(max(m, n)) ์ผํ…๋ฐ ํŒจํ„ด๋ถ„์„์ด ์ด์ƒํ•˜๊ฒŒ ๋˜์–ด ์žˆ๋„ค์š”
ํ›จ์”ฌ ๊ฐ„๋‹จํ•œ ๊ณต๊ฐ„๋ณต์žก๋„ O(1) ํ’€์ด๋„ ์žˆ์–ด์š”!

@alphaorderly alphaorderly Aug 5, 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.

class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        maze = [[1] * n for _ in range(m)]

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

        return maze[m - 1][n - 1]

์นธ ์ฑ„์šด๋‹ค๊ณ  ์ƒ๊ฐํ•˜์‹œ๋ฉด ๋ณต์žกํ•œ if ์—†์ด๋„ ์ถฉ๋ถ„ํžˆ ๊ฐ€๋Šฅํ•˜์„ธ์š”!

๊ทธ๋ฆฌ๊ณ 

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

O(1)์œผ๋กœ๋„ ํ’€์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

Comment thread unique-paths/parkhojeong.py Outdated
Comment on lines +3 to +4
row = [0] * m
grid = [row] * n

@alphaorderly alphaorderly Aug 5, 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.

์ด ๋ถ€๋ถ„์„ ์ด๋ ‡๊ฒŒ ๋งŒ๋“œ์‹œ๋ฉด ๋™์ผํ•œ row ๊ฐ์ฒด์˜ ๋ ˆํผ๋Ÿฐ์Šค๊ฐ€ ํ–‰์˜ ๊ฐœ์ˆ˜๋งŒํผ ๋ฐ˜๋ณต๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ํ•œ ํ–‰์˜ ์—ด ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜๋ฉด ๋‹ค๋ฅธ ๋ชจ๋“  ํ–‰์˜ ๊ฐ’๋„ ํ•จ๊ป˜ ๋ฐ”๋€Œ๋Š” ๋Œ€์ฐธ์‚ฌ๊ฐ€ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ์–ด์š”.

์˜ˆ๋ฅผ ๋“ค๋ฉด ์•„๋ž˜ ์ฝ”๋“œ๋Š”:

a = [0] * 5
b = [a] * 5

a[1] = 1

print(*b, sep="\n")

๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ชจ๋“  ํ–‰์˜ ๋‘ ๋ฒˆ์งธ ๊ฐ’์ด ํ•จ๊ป˜ ๋ณ€๊ฒฝ๋ฉ๋‹ˆ๋‹ค.

[0, 1, 0, 0, 0]
[0, 1, 0, 0, 0]
[0, 1, 0, 0, 0]
[0, 1, 0, 0, 0]
[0, 1, 0, 0, 0]

๊ฐ ํ–‰์„ ๋…๋ฆฝ์ ์ธ ๋ฆฌ์ŠคํŠธ๋กœ ๋งŒ๋“ค๋ ค๋ฉด ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค.

grid = [[0] * m for _ in range(n)]

๋‹ค๋งŒ ํ˜„์žฌ ํ’€์ด๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•œ ์›๋ฆฌ๋Š” 1์ฐจ์› DP๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ์‹๊ณผ ์ •ํ™•ํžˆ ๋™์ผํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์—ฌ๊ธฐ์„œ ๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ตœ์ ํ™”ํ•˜๋Š” ์•„์ด๋””์–ด๋„ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ๋– ์˜ฌ๋ฆฌ์‹ค ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”!

@parkhojeong parkhojeong Aug 6, 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.

์งš์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€๋”์”ฉ ์‹ค์ˆ˜ํ•˜๋Š” ๋ถ€๋ถ„์ธ๋ฐ ์šฐ์—ฐํžˆ ํ†ต๊ณผ๋๋„ค์š”. ํ•œ ์นผ๋Ÿผ์”ฉ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ’€์ด ์—…๋ฐ์ดํŠธ ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.

Comment thread reverse-linked-list/parkhojeong.py Outdated
prev, cur = None, head

while cur:
next = cur.next

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.

next๋Š” ํŒŒ์ด์ฌ ๋‚ด์žฅ ํ•จ์ˆ˜๋ž‘ ์ด๋ฆ„์ด ๊ฒน์ณ์„œ ( ์•„๋งˆ leetcode์—์„œ๋„ ์ƒ‰์ƒ์œผ๋กœ ๋‹ค๋ฅด๊ฒŒ ๋ณด์ด์‹ค๊ฑฐ์—์š” )
์‚ฌ์šฉ์„ ์ž์ œํ•˜์‹œ๋Š”๊ฒŒ ์–ด๋– ์‹ค๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค.

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.

๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝ ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

if matrix[row][col] == 0:
return

matrix[row][col] = MARKER

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.

ํŒŒ์ด์ฌ์ด๋ผ ๊ฐ€๋Šฅํ•˜๋‹ค์ง€๋งŒ, ์ •์ˆ˜ ํ–‰๋ ฌ์— ๋ฌธ์ž์—ด์„ ๋„ฃ๋Š”๊ฒƒ์€ ์ข€ ๋ณ„๋กœ์ด์ง€ ์•Š์„๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค.

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.

๊ฐ™์€ ํƒ€์ž… ์ค‘ ์ž…๋ ฅ ๊ฐ’ ๋ฒ”์œ„์— ํ•ด๋‹นํ•˜์ง€ ์•Š๋Š” sys.maxsize ์“ฐ๋„๋ก ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹ค.

@alphaorderly alphaorderly Aug 5, 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.

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if len(s) == 0:
            return 0

        ch_to_idx = {}
        start_idx = 0

        i = 0
        length_of_longest_substring = 1

        for i, ch in enumerate(s):
            if ch in ch_to_idx and ch_to_idx[ch] >= start_idx:
                start_idx = ch_to_idx[ch] + 1

            ch_to_idx[ch] = i
            length_of_longest_substring = max(i - start_idx + 1, length_of_longest_substring)


        return length_of_longest_substring

์ œ ์ƒ๊ฐ์—” ans๋ฅผ ๊ตฌํ•˜๋Š”๊ฒƒ์„ ๋”ฐ๋กœ ๋ถ„๋ฆฌํ•ด์„œ ๋ถ„๊ธฐ์— ๊ณตํ†ต๋กœ์ง์ด ๋งŽ์€๊ฒƒ ๋ณด๋‹ค๋Š” ์ด๋ ‡๊ฒŒ

๊ฒฝ์šฐ๋ฅผ ํฌ๊ฒŒ ๋”ฐ์ง€์ง€ ์•Š๊ณ  ์ „๋ถ€ ํ•˜๋Š”๊ฒŒ ๊ฐ€๋…์„ฑ์ด ์ข‹์ง€ ์•Š์„๊นŒ ๋ผ๋Š” ์˜๊ฒฌ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

2๊ฐœ์˜ ํ•ญ๋ชฉ์„ ๊ฐ€์ง€๋Š” max ํ•จ์ˆ˜๋Š” O(1)์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ฐ€์ง€๊ธฐ ๋•Œ๋ฌธ์— O(N) ๋ฃจํ”„ ์•ˆ์— ๋Œ๋ ค๋„ ํฐ ์„ฑ๋Šฅ์ƒ ๋ฌธ์ œ๊ฐ€ ์—†์„๊ฒƒ์œผ๋กœ ๋ณด์—ฌ์„œ์š”

@JeonJe
JeonJe self-requested a review August 5, 2026 12:11

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/parkhojeong.py
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if s == "":
            return 0

        ch_to_idx = {}
        start_idx = 0

        i = 0
        length_of_longest_substring = 1
        for i in range(len(s)):
            ch = s[i]
            if ch in ch_to_idx and ch_to_idx[ch] >= start_idx:
                start_idx = ch_to_idx[ch] + 1
                ch_to_idx[ch] = i
            else:
                ch_to_idx[ch] = i
                length_of_substring = i - start_idx + 1
                length_of_longest_substring = max(length_of_longest_substring, length_of_substring)

        return length_of_longest_substring
  • ํŒจํ„ด: Hash Map / Hash Set, Sliding Window
  • ์„ค๋ช…: ๋ฌธ์ž์—ด ๋ถ€๋ถ„๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด ํ˜„์žฌ ์ฐฝ์˜ ์‹œ์ž‘ ์ง€์ ์„ ์ด๋™์‹œํ‚ค๋ฉฐ ๊ฐ ๋ฌธ์ž ์œ„์น˜๋ฅผ ํ•ด์‹œ๋งต์œผ๋กœ ์ถ”์ ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ, ์ฐฝ์˜ ํฌ๊ธฐ๋ฅผ ์—ฐ์†์ ์œผ๋กœ ์กฐ์ •ํ•˜๋Š” Sliding Window์™€ ํ•ด์‹œ๋งต์„ ์ด์šฉํ•œ ์ค‘๋ณต ๋ฌธ์ž ๊ด€๋ฆฌ๊ฐ€ ํ•ต์‹ฌ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ํ•ด์‹œ๋งต์œผ๋กœ ๋งˆ์ง€๋ง‰ ๋“ฑ์žฅ ์ธ๋ฑ์Šค๋ฅผ ์ถ”์ ํ•˜๊ณ  ์œˆ๋„์šฐ ์‹œ์ž‘์ ์„ ์ค‘๋ณต ๋ฌธ์ž์˜ ์ด์ „ ์œ„์น˜๋กœ ๊ฐฑ์‹ ํ•œ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ length_of_longest_substring ์ดˆ๊ธฐ๊ฐ’๊ณผ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด ๊ธธ์ด ๊ณ„์‚ฐ ๋กœ์ง์—์„œ ํ˜ผ์„ ์ด ์žˆ์–ด ์‹คํ–‰ ์ค‘ ์ผ๋ถ€ ๊ฒฝ์šฐ์— ์ž˜๋ชป๋  ์ˆ˜ ์žˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ์ดˆ๊ธฐ๊ฐ’๊ณผ ๊ธธ์ด ๊ณ„์‚ฐ ๋กœ์ง์„ ๋ช…ํ™•ํžˆ ํ•˜์—ฌ ๋ชจ๋“  ๊ฒฝ์šฐ์— ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋™์ž‘ํ•˜๋„๋ก ์ˆ˜์ •ํ•˜๋ฉด ์•ˆ์ •์ ์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด length_of_substring ๋ณ€์ˆ˜๋ฅผ ํ•ญ์ƒ i - start_idx + 1๋กœ ๊ณ„์‚ฐํ•˜๊ณ , ์ƒˆ๋กœ์šด ์ค‘๋ณต ๋ฐœ๊ฒฌ ์‹œ start_idx๋ฅผ ์—…๋ฐ์ดํŠธํ•œ ๋’ค ์ตœ์žฅ ๊ธธ์ด๋ฅผ ๋ฐ˜์˜.

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

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/parkhojeong.py
class Solution:
    def numIslands(self, grid: List[List[str]]) -> int:
        row_len = len(grid)
        col_len = len(grid[0])

        def dfs(row: int, col: int):
            if not (0 <= row < row_len and 0 <= col < col_len):
                return

            if grid[row][col] == "0":
                return

            grid[row][col] = "0"
            dfs(row - 1, col)
            dfs(row + 1, col)
            dfs(row, col - 1)
            dfs(row, col + 1)

        num_islands = 0
        for row in range(row_len):
            for col in range(col_len):
                if grid[row][col] == "1":
                    num_islands += 1
                    dfs(row, col)

        return num_islands
  • ํŒจํ„ด: DFS
  • ์„ค๋ช…: DFS๋ฅผ ์ด์šฉํ•ด ์ธ์ ‘ํ•œ ๋•…('1')์„ ๋ฐฉ๋ฌธ ์ฒ˜๋ฆฌํ•˜๋ฉฐ ์„ฌ์˜ ์ˆ˜๋ฅผ ์„ธ๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์žฌ๊ท€๋ฅผ ํ†ตํ•ด ์ƒํ•˜์ขŒ์šฐ๋กœ ์—ฐ๊ฒฐ๋œ ์˜์—ญ์„ ํƒ์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.

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

๋ณต์žก๋„
Time O(rows * cols)
Space O(rows * cols)

ํ”ผ๋“œ๋ฐฑ: ์ „ํ˜•์ ์ธ DFS ๊ธฐ๋ฐ˜ ์„ฌ ํƒ์ƒ‰์œผ๋กœ ๋ชจ๋“  ์…€์„ ํ•œ ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•œ๋‹ค. ์žฌ๊ท€ ๊นŠ์ด๊ฐ€ ํฌ๊ฒŒ ์ฆ๊ฐ€ํ•˜๋ฉด ์Šคํƒ ์˜ค๋ฒ„ํ”Œ๋กœ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ์žฌ๊ท€ ๋Œ€์‹  ๋ช…์‹œ์  ์Šคํƒ์„ ์‚ฌ์šฉํ•œ 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/parkhojeong.py
# 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_node, cur_node = None, head

        while cur_node:
            next_node = cur_node.next

            cur_node.next = prev_node
            prev_node, cur_node = cur_node, next_node

        return prev_node
  • ํŒจํ„ด: Two Pointers, Linked List
  • ์„ค๋ช…: head ํฌ์ธํ„ฐ์™€ prev ํฌ์ธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฆฌ์ŠคํŠธ๋ฅผ ์—ญ์ˆœ์œผ๋กœ ์ˆœํšŒํ•˜๋ฉฐ ๋งํฌ๋ฅผ ๋’ค์ง‘๋Š” ์ „ํ˜•์ ์ธ ํŒจํ„ด์œผ๋กœ, ๋‘ ํฌ์ธํ„ฐ๋ฅผ ํ™œ์šฉํ•œ ์ˆœ์„œ ๋ฐ˜์ „(Reverse) ์ž‘์—…์ด๋‹ค.

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

๋ณต์žก๋„
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.

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

set-matrix-zeroes/parkhojeong.py
class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """

        row_len = len(matrix)
        col_len = len(matrix[0])
        MARKER = "#"

        def dfs(row, col, d_row, d_col):
            if not (0 <= row < row_len and 0 <= col < col_len):
                return 

            if matrix[row][col] == 0:
                return

            matrix[row][col] = MARKER
            dfs(row + d_row, col + d_col, d_row, d_col)

        for row in range(row_len):
            for col in range(col_len):
                if matrix[row][col] == 0:

                    matrix[row][col] = MARKER
                    dfs(row + 1, col, 1, 0)
                    dfs(row - 1, col, -1, 0)
                    dfs(row, col + 1, 0, 1)
                    dfs(row, col - 1, 0, -1)

        for row in range(row_len):
            for col in range(col_len):
                if matrix[row][col] == MARKER:
                    matrix[row][col] = 0
  • ํŒจํ„ด: Depth-First Search, Greedy
  • ์„ค๋ช…: ์ฝ”๋“œ๋Š” ๊ฐ 0์ธ ์›์†Œ๋ฅผ ์ค‘์‹ฌ์œผ๋กœ ์ธ์ ‘ํ•œ ๋น„์ œ๋กœ ๊ฐ’์„ MARKER๋กœ ํ‘œ์‹œํ•˜๋ฉฐ DFS๋กœ ์—ฐ๊ฒฐ ๊ฒฝ๋กœ๋ฅผ ํƒ์ƒ‰ํ•ด 0์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค. ์ „์ฒด์ ์œผ๋กœ๋Š” ์—ฐ๊ฒฐ ํƒ์ƒ‰๊ณผ ํ‘œ์‹ ํ›„ ์žฌ์ฒ˜๋ฆฌ์˜ ํ๋ฆ„์ด๋ฏ€๋กœ DFS์™€ ๊ฐ„๋‹จํ•œ ํ‘œ์‹ ์ „๋žต์ด ํ•ต์‹ฌ ํŒจํ„ด์ž…๋‹ˆ๋‹ค.

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

๋ณต์žก๋„
Time O(rows * cols)
Space O(rows * cols)

ํ”ผ๋“œ๋ฐฑ: ํ˜„์žฌ ๊ตฌํ˜„์€ ๋งˆ์ปค๋กœ DFS๋ฅผ ํ™œ์šฉํ•ด ์—ฐ์‡„์ ์œผ๋กœ 0์œผ๋กœ ๋ฐ”๊พธ๋Š” ๋น„ํšจ์œจ์  ๊ตฌ์กฐ๋ฅผ ๋ณด์ธ๋‹ค. ์—ฌ๋Ÿฌ ๋ฐฉํ–ฅ์œผ๋กœ ํ™•์‚ฐ์‹œํ‚ค๋Š” DFS๊ฐ€ ํ•„์š” ์ด์ƒ์œผ๋กœ ์ค‘๋ณต ๋ฐฉ๋ฌธ์„ ์œ ๋ฐœํ•  ์ˆ˜ ์žˆ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ‘œ์ค€ ์ ‘๊ทผ์ธ ์ฒซ ํ†ต๊ณผ์—์„œ ํ–‰/์—ด ๋ฐฐ์—ด์— ํ”Œ๋ž˜๊ทธ๋ฅผ ๋‚จ๊ฒจ ๋‘๊ณ , ํ›„์ฒ˜๋ฆฌ์—์„œ 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.

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

unique-paths/parkhojeong.py
class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        column = [1] * m

        for col in range(n - 1):

            for row in range(1, m):
                column[row] = column[row] + column[row - 1]

        return column[-1]
  • ํŒจํ„ด: Dynamic Programming, Greedy
  • ์„ค๋ช…: 2์ฐจ์› ๊ฒฉ์ž์—์„œ์˜ ๊ฒฝ๋กœ ์ˆ˜๋ฅผ ์—ด๊ณผ ํ–‰์˜ ํ•ฉ์œผ๋กœ ๊ฐฑ์‹ ํ•˜๋Š” DP ์•„์ด๋””์–ด๋กœ, ๋ฉ”๋ชจ๋ฆฌ ์ ˆ์•ฝ์„ ์œ„ํ•ด 1์ฐจ์› ๋ฐฐ์—ด์„ ํ™œ์šฉํ•˜๋Š” ํŒจํ„ด์ž…๋‹ˆ๋‹ค. ๊ฒฝ๋กœ์˜ ํ•ฉ ๊ทœ์น™์„ ์ด์šฉํ•œ ์ ํ™”์‹์˜ ์ „ํ˜•์  ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: 1์ฐจ์› DP ๋ฐฐ์—ด๋กœ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ์„ ์ตœ์†Œํ™”ํ•œ ์ ์€ ์ข‹๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ๋ช…ํ™•์„ฑ์„ ์œ„ํ•ด ์ฃผ์„์œผ๋กœ ์ ํ™”์‹์„ ์ถ”๊ฐ€ํ•˜๋ฉด ์ดํ•ด๋„๊ฐ€ ์ƒ์Šนํ•œ๋‹ค.

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

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/parkhojeong.py
class Solution:
    def setZeroes(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """

        row_len = len(matrix)
        col_len = len(matrix[0])
        MARKER = sys.maxsize

        def dfs(row, col, d_row, d_col):
            if not (0 <= row < row_len and 0 <= col < col_len):
                return

            if matrix[row][col] == 0:
                return

            matrix[row][col] = MARKER
            dfs(row + d_row, col + d_col, d_row, d_col)

        for row in range(row_len):
            for col in range(col_len):
                if matrix[row][col] == 0:

                    matrix[row][col] = MARKER
                    dfs(row + 1, col, 1, 0)
                    dfs(row - 1, col, -1, 0)
                    dfs(row, col + 1, 0, 1)
                    dfs(row, col - 1, 0, -1)

        for row in range(row_len):
            for col in range(col_len):
                if matrix[row][col] == MARKER:
                    matrix[row][col] = 0
  • ํŒจํ„ด: Depth-First Search, Backtracking
  • ์„ค๋ช…: ์ฝ”๋“œ๊ฐ€ ๊ฐ 0์ธ ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ƒํ•˜์ขŒ์šฐ๋กœ ํƒ์ƒ‰ํ•˜๋ฉฐ ์ธ์ ‘ ์›์†Œ๋ฅผ ํ‘œ์‹œํ•˜๋Š” DFS ํ๋ฆ„์„ ์‚ฌ์šฉํ•˜๊ณ , ํ‘œ์‹œ๋œ ๊ฐ’์„ ๋‚˜์ค‘์— 0์œผ๋กœ ๋˜๋Œ๋ฆฌ๋Š” ๋ฐฉ์‹์ด Backtracking ์„ฑ๊ฒฉ๊ณผ DFS ํŒจํ„ด์„ ํ•จ๊ป˜ ๋ณด์ž…๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: 0์ด ์žˆ๋Š” ์œ„์น˜๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ธ์ ‘ ๋ฐฉํ–ฅ์œผ๋กœ ํƒ์ƒ‰ํ•ด MARKER๋ฅผ ๊ฑฐ์ณ ๊ฐ„์ ‘์ ์œผ๋กœ ํ‘œ์‹œํ•œ๋‹ค. ํ•˜์ง€๋งŒ ๋ชจ๋“  0์„ ์ฐพ๊ณ  ๋งˆ์ปค ์ฒ˜๋ฆฌ๊นŒ์ง€ ๊ฐ€๋Šฅํ•˜๋ฏ€๋กœ ์ด ์‹œ๊ฐ„์€ ์ด์ค‘ ๋ฃจํ”„๋กœ ๊ฒฐ์ •๋˜๊ณ  ๊ณต๊ฐ„์€ ์ถ”๊ฐ€ ๋ฐฐ์—ด ์—†์ด ๋งˆ์ปค๋ฅผ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„ํ•œ๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ํ˜„์žฌ ๊ตฌํ˜„์€ in-place ์ฒ˜๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‚˜, 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.

2 participants