Skip to content

[sangbeenmoon] WEEK 02 Solutions#2704

Merged
sangbeenmoon merged 9 commits into
DaleStudy:mainfrom
sangbeenmoon:main
Jul 5, 2026
Merged

[sangbeenmoon] WEEK 02 Solutions#2704
sangbeenmoon merged 9 commits into
DaleStudy:mainfrom
sangbeenmoon:main

Conversation

@sangbeenmoon

@sangbeenmoon sangbeenmoon commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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

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

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

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

Important

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

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

@dalestudy

dalestudy Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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

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

๋ฌธ์ œ ๋‚œ์ด๋„ ์œ ํ˜• ๋ถ„์„
3sum Medium โš ๏ธ ์œ ํ˜• ๋ถˆ์ผ์น˜
validate-binary-search-tree Medium โœ… ์˜๋„ํ•œ ์œ ํ˜•

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

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

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

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

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

๐Ÿ”ข API ์‚ฌ์šฉ๋Ÿ‰ (gpt-5-nano)
์š”์ฒญ ์ž…๋ ฅ ํ† ํฐ ์ถœ๋ ฅ ํ† ํฐ ํ•ฉ๊ณ„ ๋น„์šฉ
1 1,318 74 1,392 $0.000096
2 1,334 74 1,408 $0.000096
ํ•ฉ๊ณ„ 2,652 148 2,800 $0.000192

@DaleSeo

DaleSeo commented Jul 4, 2026

Copy link
Copy Markdown
Member

@parkhojeong parkhojeong left a comment

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.

์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค! ๋ช‡ ๊ฐ€์ง€ ๊ฐœ์„  ํฌ์ธํŠธ ์ปค๋ฉ˜ํŠธ๋กœ ๋‚จ๊ฒจ๋ณด์•˜์–ด์š” :)
๋‹ฌ๋ ˆ๋‹˜ ์ปค๋ฉ˜ํŠธ(ํ”„๋กœ์ ํŠธ ์ฃผ์ฐจ ์„ค์ •) ํ™•์ธํ•ด์ฃผ์‹œ๋ฉด ๋  ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค~

Comment on lines +60 to +74
def isValid(mm, MM, cur: TreeNode) -> bool:


if cur == None:
return True

if mm != None and cur.val <= mm:
return False

if MM != None and cur.val >= MM:
return False

return isValid(mm, cur.val, cur.left) and isValid(cur.val, MM, cur.right)

return isValid(None, None ,root)

@parkhojeong parkhojeong Jul 4, 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.

None์€ is ๋กœ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๊ถŒ์žฅ๋˜์–ด์„œ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์š”!
Comparisons to singletons like None should always be done with is or is not, never the equality operators.
https://peps.python.org/pep-0008/#programming-recommendations

๊ทธ๋ฆฌ๊ณ  ๋ณ€์ˆ˜๋ช…์€ mm, MM์ด ์–ด๋–ค ๊ฐ’์ธ์ง€ ์•Œ๊ธฐ๊ฐ€ ์–ด๋ ค์›Œ์„œ ์˜๋ฏธ๋ฅผ ๋‹ด์•„ ๋ณด์•„๋„ ์ข‹์„ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค :)

Suggested change
def isValid(mm, MM, cur: TreeNode) -> bool:
if cur == None:
return True
if mm != None and cur.val <= mm:
return False
if MM != None and cur.val >= MM:
return False
return isValid(mm, cur.val, cur.left) and isValid(cur.val, MM, cur.right)
return isValid(None, None ,root)
def isValid(max_val, min_val, cur: TreeNode) -> bool:
if cur is None:
return True
if max_val is not None and cur.val <= max_val:
return False
if min_val is not None and cur.val >= min_val:
return False
return isValid(max_val, cur.val, cur.left) and isValid(cur.val, min_val, cur.right)
return isValid(None, None, root)

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 3sum/sangbeenmoon.py
Comment on lines +52 to +57
while left < right:
if nums[left] + nums[right] == target:
candidate = (target * -1, nums[left], nums[right])
if candidate not in answer_map:
answer_map[candidate] = True
answer.append([target * -1, nums[left], nums[right]])

@parkhojeong parkhojeong Jul 4, 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.

ํ•ด์‹œ๋งต์„ ์‚ฌ์šฉํ•ด์„œ candidate๋ฅผ ๋‹ด์•„์„œ ์ค‘๋ณต์„ ์ฒดํฌํ•˜์…จ๊ตฐ์š”!
์ด๋ฏธ ์ •๋ ฌ์ด ๋œ ์ƒํƒœ๋ผ์„œ nums[left] == nums[left+1] ์ธ ์ผ€์ด์Šค๋ฅผ ์Šคํ‚ตํ•ด์ฃผ๋ฉด(right๋„ ๋™์ผ) candidate๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  not in ๋กœ์ง์„ ์•ˆํƒ€๊ธฐ ๋•Œ๋ฌธ์— ๋” ์ตœ์ ํ™”๊ฐ€ ๊ฐ€๋Šฅํ•  ๊ฑฐ ๊ฐ™์•„์š”!

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 3sum/sangbeenmoon.py
Comment on lines +55 to +58
if candidate not in answer_map:
answer_map[candidate] = True
answer.append([target * -1, nums[left], nums[right]])
left += 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.

์„ฑ๊ณตํ•œ ๊ฒฝ์šฐ right -= 1 ๋„ ํ•จ๊ป˜ ํ•ด์ฃผ๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์š”!

Comment thread 3sum/sangbeenmoon.py
Comment on lines +46 to +50
for i in range(len(nums)):
target = -1 * nums[i]

left = i + 1
right = len(nums) - 1

@parkhojeong parkhojeong Jul 4, 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.

์ •๋ ฌ์ด ๋œ ์ƒํƒœ๋ผ nums[i] ์™€ nums[i - 1] ์ด ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์Šคํ‚ตํ•ด์ฃผ๊ณ  nums[i] > 0 ์ด ๋œ ์ƒํƒœ์—์„œ๋Š” break ํ•ด์ฃผ๋ฉด ์ตœ์ ํ™”๊ฐ€ ๊ฐ€๋Šฅํ•  ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค :)

ex. [ -2, -1, -1, -1, 0, 1, 2, 3] , -1์ด ํ•œ๋ฒˆ์ธ ๊ฒฝ์šฐ๋งŒ ์‹คํ–‰ํ•˜๊ณ  ์ดํ›„๋Š” ์Šคํ‚ต, nums[i]๊ฐ€ 0๋ณด๋‹ค ์ปค์ง€๋ฉด ์–‘์ˆ˜ + ์–‘์ˆ˜ + ์–‘์ˆ˜ ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ข…๋ฃŒ

@alphaorderly alphaorderly left a comment

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.

๊น”๋”ํ•˜๊ฒŒ ์ž˜ ํ•ด๊ฒฐํ•˜์‹ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! ๊ณ ์ƒํ•˜์…จ์–ด์š”!

Comment thread 3sum/sangbeenmoon.py

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, Hash Map / Hash Set
  • ์„ค๋ช…: ์‚ผํ•ฉ(3Sum) ๋ฌธ์ œ์—์„œ ์ •๋ ฌ ํ›„ ์–‘ ๋ ํฌ์ธํ„ฐ๋ฅผ ์ด๋™ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํƒ์ƒ‰ํ•˜๋ฏ€๋กœ Two Pointers ํŒจํ„ด์ด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ์œ„ํ•ด Hash Map/Hash Set๋ฅผ ํ™œ์šฉํ•ด ๊ฒฐ๊ณผ ์ค‘๋ณต์„ ๋ฐฉ์ง€ํ•˜๋Š” ๋ถ€๋ถ„์ด ์žˆ์Šต๋‹ˆ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ์ •๋ ฌ ํ›„ ์™ธ๋ถ€ ๋ฃจํ”„์™€ ๋‚ด๋ถ€ ํˆฌ ํฌ์ธํ„ฐ๋กœ ๋ณต์žก๋„๋ฅผ ๋‹ฌ์„ฑํ–ˆ๋‹ค. ๋‹ค๋งŒ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ visited๋กœ ์ถ”๊ฐ€ํ–ˆ๋Š”๋ฐ, ์ „์ฒด์ ์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ํ•ด์‹œ๋งต ์‚ฌ์šฉ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋‹ค. ๋‘ ๋ฒˆ์งธ ๊ตฌํ˜„์ฒ˜๋Ÿผ ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ๋” ๊ฐ„๊ฒฐํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•˜๋Š” ํŽธ์ด ์ข‹๋‹ค.

๊ฐœ์„  ์ œ์•ˆ: ๊ณ ๋ คํ•ด๋ณผ ๋งŒํ•œ ๋Œ€์•ˆ: ์ค‘๋ณต ์ œ๊ฑฐ๋ฅผ ๋ฆฌ์ŠคํŠธ ์Šคํ‚ต ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ  ํ•ด์‹œ๋งต ์—†์ด๋„ ์ค‘๋ณต ์—†๋Š” ๊ฒฐ๊ณผ๋ฅผ ์–ป๋„๋ก ๊ตฌํ˜„์„ ๋‹จ์ˆœํ™”

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, Binary Search, Hash Map / Hash Set
  • ์„ค๋ช…: ์ฒซ ๋ฒˆ์งธ ์ฝ”๋“œ๋Š” ์žฌ๊ท€๋กœ BST์˜ ๊ฐ ๋…ธ๋“œ๋ฅผ ํƒ์ƒ‰ํ•˜๋ฉฐ ์ž์‹ ๋…ธ๋“œ๊ฐ€ ํŠน์ • ๋ฒ”์œ„ ์•ˆ์— ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. ๋‘ ๊ฐ€์ง€ ๊ตฌํ˜„ ๋ชจ๋‘ ํŠธ๋ฆฌ ๊ตฌ์กฐ์˜ ๊ฐ ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•˜๋Š” DFS ํŒจํ„ด์ด๋ฉฐ, ์ž์‹ ๋…ธ๋“œ์˜ ๊ฐ’ ๋ฒ”์œ„๋ฅผ ์ œํ•œํ•ด BST ํŠน์„ฑ์„ ๊ฒ€์‚ฌํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ๋‘ ๋ฒˆ์งธ ๊ตฌํ˜„์€ min/max ๋ฒ”์œ„ ์ถ”์ ์„ ํ†ตํ•œ Divide and Conquer์‹ DFS๋กœ BST ์—ฌ๋ถ€๋ฅผ ํŒ๋‹จํ•œ๋‹ค.

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

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

ํ”ผ๋“œ๋ฐฑ: ๋‘ ๊ฐ€์ง€ ๊ตฌํ˜„์ด ์„ž์—ฌ ์žˆ๋Š”๋ฐ, ์ฒซ ๋ฒˆ์งธ ๊ตฌํ˜„์€ ์ „์—ญ ์ƒํƒœ๋ฅผ ์ด์šฉํ•ด ์žฌ๊ท€์ ์œผ๋กœ ๋ฒ”์œ„๋ฅผ ๊ฒ€์‚ฌํ•œ๋‹ค. ๋‘ ๋ฒˆ์งธ๋Š” ์žฌ๊ท€์ ์œผ๋กœ ๋ฒ”์œ„๋ฅผ ๋„˜๊ฒจ์ฃผ๋Š” ์ผ๋ฐ˜์ ์ธ ํŒจํ„ด์œผ๋กœ ์•ˆ์ •์ ์ด๋‹ค.

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

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

@sangbeenmoon sangbeenmoon merged commit c620f71 into DaleStudy:main Jul 5, 2026
1 check passed
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.

4 participants