Skip to content

[novacat25] WEEK 02 Solutions - #2933

Open
novacat25 wants to merge 17 commits into
DaleStudy:mainfrom
novacat25:week2
Open

novacat25 wants to merge 17 commits into
DaleStudy:mainfrom
novacat25:week2

Conversation

@novacat25

@novacat25 novacat25 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

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

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

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

Important

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

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

@dalestudy

dalestudy Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

๐Ÿค– AI ๋ฆฌ๋ทฐ(์•Œ๊ณ ๋ฆฌ์ฆ˜ ํŒจํ„ด, ์‹œ๊ฐ„/๊ณต๊ฐ„ ๋ณต์žก๋„, ํ•™์Šต ํ˜„ํ™ฉ) ๊ฒฐ๊ณผ๋Š” Checks ํƒญ์—์„œ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.

@novacat25 novacat25 changed the title Week2 [novacat25] WEEK 02 Solutions Nov 16, 2026

@Yu-Jaeyoung Yu-Jaeyoung 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.

์•ˆ๋…•ํ•˜์„ธ์š”? ํ‰์†Œ TypeScript๋ฅผ ์ข‹์•„ํ•ด์„œ comments ๋‚จ๊ธฐ๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์•„์ง ํ’€์ด๋ฅผ valid-anagram๊นŒ์ง€ ๋ฐ–์— ์•ˆํ•œ ์ƒํƒœ๋ผ, ์ด์— ๋Œ€ํ•œ comment๋งŒ ์งง๊ฒŒ ๋‚จ๊ฒจ๋ณด์•˜์Šต๋‹ˆ๋‹ค.

๋งค์ฃผ ์ฐพ์•„์™€์„œ ์—ด์‹ฌํžˆ comment ๋‚จ๊ธฐ๊ณ , ์ €๋„ ๊ฐœ์ธ์ ์œผ๋กœ TS ํ’€์ด ์ง„ํ–‰ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ข‹์€ ํ•˜๋ฃจ๋ณด๋‚ด์„ธ์š” ๐Ÿ‘๐Ÿป

return true
}

// ๊ธฐ์กด ํ’€์ด/์ œ์ถœ ๋‚ด์—ญ.

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.

AI Reviewer๋Š” '์ฃผ์„ ์žˆ์œผ๋ฉด ๊ฐ€๋…์„ฑ ๋–จ์–ด์ง€๋‹ˆ ์ง€์šฐ๋ผ'๊ณ  ํ•˜์ง€๋งŒ,
๊ทธ๋ž˜๋„ ์Šค์Šค๋กœ ํ•™์Šตํ•œ ๋ถ€๋ถ„์€ ๋˜ ๋‚จ๊ธฐ๊ณ  ์‹ถ์–ด์ง€๋”๋ผ๊ณ ์š” ใ…Žใ…Ž

Comment thread valid-anagram/novacat25.ts Outdated
@@ -0,0 +1,151 @@
/*
์‹œ๊ฐ„ ๋ณต์žก๋„(TC): O(n)
๊ณต๊ฐ„ ๋ณต์žก๋„(SC): O(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.

3ํŠธ์—์„œ ๊ณต๊ฐ„๋ณต์žก๋„๋ฅผ 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.

ํ‘œ๊ธฐ๋ฅผ ํ—ท๊ฐˆ๋ ธ๋„ค์š”. ๊ณ ์ณค์Šต๋‹ˆ๋‹ค!

const isAnagram = (s: string, t: string): boolean => {
if(s.length !== t.length) return false
const anagramMap = new Map<string, number>()

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.

Map์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๊ณต๊ฐ„ ๋ณต์žก๋„๋Š” ๋†’์ง€๋งŒ,
TypeScript ๋‹ต๊ฒŒ ์ž‘์„ฑ๋œ ๋ฌธ๋ฒ•์ธ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ˜†

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 valid-anagram/novacat25.ts Outdated
if (s.length !== t.length) return false

const BASE_CHAR_CODE = "a".charCodeAt(0)
const countArr = new Array(26).fill(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.

new Array<number>(26).fill(0) ์œผ๋กœ ์ž‘์„ฑํ•ด์„œ ํƒ€์ž…์„ ๋ช…ํ™•ํ•˜๊ฒŒ ํ•˜๋Š”๊ฑด ์–ด๋–จ๊นŒ์š”?
์‚ฌ๋žŒ์ด ์ž‘์„ฑํ•˜๋‹ค ๋ณด๋ฉด ๋’ค์—์„œ ์‹ค์ˆ˜ ํ• ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„ ์˜๊ฒฌ ๋‚จ๊ฒจ๋ด…๋‹ˆ๋‹ค !

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.

์˜ค, ํ™•์‹คํžˆ ์ด ๋ถ€๋ถ„ any[]๋กœ ๋œน๋‹ˆ๋‹ค..!
const countArr: number[]๋กœ๋„ ๊ฐ€๋Šฅํ•˜๊ฒ ์ง€๋งŒ, ๋กœ Generic์„ ์ด์šฉํ•ด์„œ๋„ ๊ณ ์น  ์ˆ˜ ์žˆ์—ˆ๊ตฐ์š”.
ํ•˜๋‚˜ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค!

Comment thread valid-anagram/novacat25.ts Outdated
return false
}

countArr[code - BASE_CHAR_CODE]--

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.

์•ˆ๋…•ํ•˜์„ธ์š” @novacat25 ๋‹˜ :)
์ €๋Š” s, t ๋ฐฐ์—ด์„ ๊ฐ๊ฐ ๋งŒ๋“ค์–ด ๋งˆ์ง€๋ง‰์— ๋น„๊ตํ–ˆ๋Š”๋ฐ, ๋ฐฐ์—ด ํ•˜๋‚˜์—์„œ t๋ฅผ ๋นผ๋‹ค๊ฐ€ 0 ์ดํ•˜๊ฐ€ ๋˜๋Š” ์ˆœ๊ฐ„ ๋ฐ”๋กœ false๋ฅผ ๋ฐ˜ํ™˜ํ•ด์„œ ๋๊นŒ์ง€ loop๋ฅผ ๋Œ์ง€ ์•Š์•„๋„ ๋˜๋Š” ์ ์ด ์ธ์ƒ์ ์ž…๋‹ˆ๋‹ค ๐Ÿ™‚
13์ค„์˜ ๊ธธ์ด ๋น„๊ต๊ฐ€ ์—†์—ˆ๋‹ค๋ฉด ๋งˆ์ง€๋ง‰์— ์ „๋ถ€ 0์ธ์ง€ ํ™•์ธํ•˜๋Š” ์ค„์ด ํ•„์š”ํ–ˆ์„ ํ…๋ฐ, ๊ธธ์ด ๋น„๊ต ๋•๋ถ„์— ๊ทธ ๊ณผ์ •์„ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ์กฐ๋ผ ๊น”๋”ํ–ˆ์Šต๋‹ˆ๋‹ค.
ํŒŒ์ด์ฌ์˜ ord(-)๋กœ ๋ฌธ์ž ์ฝ”๋“œ๋ฅผ ๊ตฌํ•˜๋Š” ๋ถ€๋ถ„์ด TS์—์„œ๋Š” -.charCodeAt(0)์— ๋Œ€์‘๋˜๋Š”๊ตฐ์š”!

์‚ฌ์†Œํ•˜์ง€๋งŒ code - BASE_CHAR_CODE๊ฐ€ 25์ค„๊ณผ 31์ค„์—์„œ ๋‘ ๋ฒˆ ๊ณ„์‚ฐ๋˜์–ด์„œ, idx ๊ฐ™์€ ๋ณ€์ˆ˜๋กœ ํ•œ ๋ฒˆ๋งŒ ๊ตฌํ•ด ๋‘๋ฉด ๋” ๊น”๋”ํ•  ๊ฒƒ ๊ฐ™์•„์š”.

์ œ ํ’€์ด์— ๋„์›€ ์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!

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.

๋„์›€์ด ๋˜์…จ๋‹ค๋‹ˆ ๋‹คํ–‰์ž…๋‹ˆ๋‹ค!
์ด์ชฝ์€ ์ฐธ๊ณ ๋กœ ์•„์˜ˆ ์ „์—ญ์œผ๋กœ ๋นผ๊ณ , getCodeIndex ๋ถ€๋ถ„์„ ๋ฉ”์†Œ๋“œํ™”๋กœ ๋‘˜๋ €์–ด์š”.
Reusability๋ฅผ ์กฐ๊ธˆ ๋” ์ค‘์‹œํ•˜๊ธด ํ–ˆ์Šต๋‹ˆ๋‹ค.

const BASE_CHAR_CODE = "a".charCodeAt(0)

const getCodeIndex = (code: number) => code - BASE_CHAR_CODE

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.

์•„ํ•˜, getCodeIndex๋กœ ๋ถ„๋ฆฌํ•ด์„œ ์ „์—ญ ํ•จ์ˆ˜๋กœ ๋‘๋‹ˆ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ๋” ์šฉ์ดํ•œ ๊ฒƒ ๊ฐ™๋„ค์š”!
์„ค๋ช… ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Comment on lines +50 to +76
/* 2ํŠธ: Memoisation ํ™œ์šฉ(Top-down DP)
const countRecur = (n: number, memo: number[]) => {
// Base case
if (n < 0)
return 0
if (n === 0)
return 1
// If value is memoised
if (memo[n] !== -1) {
return memo[n]
}
// Memoise the state (dp[n] = dp[n-1] + dp[n-2])
memo[n] = countRecur(n - 1, memo) +
countRecur(n - 2, memo)
return memo[n]
}
const memoisedClimbStairs = (n: number) => {
const memo = Array(n + 1).fill(-1)
return countRecur(n, memo)
}
*/

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.

์ €๋ž‘ ํ’€์ด ํžˆ์Šคํ† ๋ฆฌ๊ฐ€ ๊ต‰์žฅํžˆ ๋น„์Šทํ•˜๋„ค์š”..! ์—ฌ๋‹ด์ด์ง€๋งŒ ์ €๋„ 2ํŠธ์— Top-down DP๋กœ ํ’€์—ˆ์—ˆ์Šต๋‹ˆ๋‹ค...
์ €๋Š” 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋ฉด ๊ณ„๋‹จ ์ˆ˜์™€ ๋งค์นญ์ด ์•ˆ ๋˜์–ด์„œ 1์นธ, 2์นธ์˜ ๋‹ต์„ ์ง์ ‘ ๋„ฃ๊ณ  ์‹œ์ž‘ํ–ˆ๋Š”๋ฐ,
nova๋‹˜๊ป˜์„œ๋Š” ๋‚จ์€ ๊ณ„๋‹จ ์ˆ˜๊ฐ€ 0์ด๋ฉด 1, ์Œ์ˆ˜๋ฉด ์ด๋ฏธ ๋„์ฐฉ ์ง€์ ์„ ๋„˜์–ด๊ฐ„ ๊ฒƒ์ด๋ผ 0์œผ๋กœ ์ฒ˜๋ฆฌํ•˜์…”์„œ, ์ €์ฒ˜๋Ÿผ 1์นธ, 2์นธ์„ ๋”ฐ๋กœ ์„ธํŒ…ํ•  ํ•„์š”๊ฐ€ ์—†๊ฒ ๋„ค์š”!
๊ทธ๋ฆฌ๊ณ  ์ €๋Š” ๋ฉ”๋ชจ(์ œ ํ’€์ด์—์„œ๋Š” dp์— ๋Œ€์‘)๋ฅผ ๋ชจ๋‘ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ–ˆ๋Š”๋ฐ, -1๋กœ ์ดˆ๊ธฐํ™”ํ•˜๋ฉด ๋” ์•ˆ์ „ํ•  ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ™‚

@novacat25 novacat25 Nov 17, 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.

๋ฐฐ์—ด๋กœ์„œ '๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ๊ฐ’'์ด ํ™•์‹คํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, -1์ด ํ™•์‹คํžˆ ์ œ์ผ ์•ˆ์ „ํ•˜๊ธด ํ•˜์ง€์š”.
๊ทธ๋ž˜๋„ Bottom-up ๋ฐฉ์‹์ด๋‚˜ Tabulation ๋ฐฉ์‹ ์ „๋ถ€ n < 0์ธ ๊ฒฝ์šฐ(์œ ํšจํ•˜์ง€ ์•Š์€ ์œ„์น˜) 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•˜๊ธฐ ๋•Œ๋ฌธ์—,
if(memo[n] !== 0)๋„ ์ถฉ๋ถ„ํžˆ ์žˆ์„ ๋ฒ•ํ•œ ๋กœ์ง์ด์ง€ ์•Š๋‚˜ ์‹ถ์Šต๋‹ˆ๋‹ค.

dp[0] = 1(์•„๋ฌด ์ด๋™ ํ•˜์ง€ ์•Š๊ณ  ์ถœ๋ฐœ์ ),
dp[1] = 1(์ผ๋‹จ ํ•œ ์นธ ์ด๋™)

๊นŒ์ง€๋Š” ๊ฑฐ์˜ ๋‹ค ๊ฐ™์œผ๋‹ˆ๊นŒ์š”.

๊ทธ๋ฆฌ๊ณ  ์ ํ™”์‹ ํŠน์ง• ์ƒ n-1, n-2 ๊ฐ’์„ ๋ฏธ๋ฆฌ ๊ณ„์‚ฐํ•ด๋‘๊ณ 
i = 3๋ถ€ํ„ฐ iteration ๋„๋Š” ๋ฐฉ๋ฒ•๋„ ์•Œ๊ณ ๋‹ฌ๋ ˆ ๋งํฌ์—๋„ ์†Œ๊ฐœ๋˜์–ด ์žˆ๋‹ค ๋ณด๋‹ˆ, ์•„์ฃผ ๋ฏธ์„ธํ•œ ๋””ํ…Œ์ผ์ฐจ ์•„๋‹๊นŒ ์‹ถ๋„ค์š” ใ…Žใ…Ž

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.

๋ง์”€ ๋“ฃ๊ณ  ๋ณด๋‹ˆ ๊ทธ๋ ‡๋„ค์š”..!
๋ณดํŽธ์ ์œผ๋กœ๋Š” -1์„ ๊ธฐ์ค€์œผ๋กœ ๋‘๋Š” ํŽธ์ด์ง€๋งŒ, ์ด ๋ฌธ์ œ์ฒ˜๋Ÿผ n < 0์„ 0์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ตฌ์กฐ๋ผ๋ฉด 0์œผ๋กœ ๋‘์–ด๋„ ์ถฉ๋ถ„ํžˆ ์„ฑ๋ฆฝํ•˜๊ฒ ๋„ค์š”.
์•Œ๊ณ ๋‹ฌ๋ ˆ ํ’€์ด๋„ ๊ฐ™์ด ํ™•์ธํ•ด์„œ ์ ๊ฒ€ํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค~

Comment on lines +28 to +34
for (let i = 2; i <= n; i++) {
const current = prev1 + prev2

prev2 = prev1
prev1 = current
}

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.

์ตœ์ข… ์ œ์ถœํ•˜์‹  ํ’€์ด๋Š” ์ €์™€ ๊ตฌ์กฐ๋Š” ๋™์ผํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค
์ €๋Š” ํŒŒ์ด์ฌ์ด๋‹ค๋ณด๋‹ˆ first, second = second, first + second์ฒ˜๋Ÿผ ํŠœํ”Œ๋กœ ํ‘œํ˜„ํ–ˆ๋Š”๋ฐ,
๊ถ๊ธˆํ•ด์„œ ์ฐพ์•„๋ณด๋‹ˆ ts์—์„œ๋Š” ์‰ผํ‘œ๋งŒ ์“ฐ๊ฑฐ๋‚˜(์†Œ๊ด„ํ˜ธ ์ง€์›๋„ ์•ˆ ๋˜๋„ค์š”!), [prev2, prev1] = [prev1, current]์ฒ˜๋Ÿผ ๋Œ€๊ด„ํ˜ธ๋กœ ์จ์•ผ ์ž‘๋™ํ•˜๋„ค์š”..
29~32์ค„์„ current ์—†์ด [prev2, prev1] = [prev1, prev1 + prev2] ํ•œ ์ค„๋กœ ์ค„์ผ ์ˆ˜๋„ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š”:)

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.

  for (let i = 2; i <= n; i++) {
    ;[prev2, prev1] = [prev1, prev1 + prev2]
  }

๋„ค, ์ด ๋ถ€๋ถ„์€ ๋ง์”€๋Œ€๋กœ current๊ฐ€ ์—†์–ด์ง€๋Š” ๋งŒํผ ํ•œ์ค„๋กœ ์ค„์—ฌ์ง€๋„ค์š”.
Prettier๊ฐ€ ์ฝ”๋“œ๋ฅผ ์ €์žฅํ•  ๋•Œ๋งˆ๋‹ค ์ฝ”๋“œ ์Šคํƒ€์ผ์„ ์žก์•„์คฌ๋Š”๋ฐ, ์•ž์— ;๊ฐ€ ๋ถ™์€ ๊ฒŒ ์ธ์ƒ์ ์ด์—ˆ์Šต๋‹ˆ๋‹ค.

๋‹ค๋งŒ, ์ด ๋ถ€๋ถ„์€ ํ™•๋‹ต์ด ํž˜๋“ค ๊ฒƒ ๊ฐ™๋„ค์š”..
prev2์—๊ฒŒ prev1 ๊ฐ’์„ ๋ฎ๊ณ , prev1์ด current๋ฅผ ๋ฐ›๋Š”๋‹ค๋Š” ๋ช…์‹œ์ ์ธ ์˜๋ฏธ ์ „๋‹ฌ์— ์žˆ์–ด์„œ ์ง€๊ธˆ ๋ฐฉ์‹์ด ์กฐ๊ธˆ ๋” ํ™•์‹คํ•˜๋‹ค๊ณ  ๋А๊ผˆ๊ฑฐ๋“ ์š”!

๊ทธ๋ž˜์„œ ์ด ๋ถ€๋ถ„์€ ์กฐ๊ธˆ ๋” ๊ณ ๋ฏผ์ด ํ•„์š”ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
๊ทธ๋ž˜๋„ ๋Œ€์•ˆ์ด ํ•˜๋‚˜ ์ƒ๊ฒจ์„œ ๋ฐฐ์›Œ๊ฐ€๋„ค์š”.

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 on lines +20 to +23
if (i === START_IDX) {
resultArr[i] = 1
continue
}

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.

์ €๋Š” ์™ผ์ชฝ ๋ˆ„์ ๊ณฑ์€ i = 0์„ ์ œ์™ธํ•˜๊ณ  i = 1๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๊ณ , ์˜ค๋ฅธ์ชฝ์€ ๋งˆ์ง€๋ง‰ ์นธ์—๋„ 1์„ ๊ณฑํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ–ˆ๋Š”๋ฐ, ๊ณฑํ•  ์›์†Œ๊ฐ€ ์—†๋Š” ์–‘ ๋์—์„œ continue๋กœ ๊ฑด๋„ˆ๋›ฐ์…จ๋„ค์š”!

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.

์•„, ์ด ๋ถ€๋ถ„์€ ์ž‘์„ฑ ๋‹น์‹œ์— ์กฐ๊ธˆ ๋” ์˜๋ฏธ๋ฅผ ํ™•์‹คํ•˜๊ฒŒ ํ•˜๊ณ  ์‹ถ์–ด์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•œ ๊ฑฐ๊ธด ํ•ด์š”!
๋ง์”€๋Œ€๋กœ i = 1๋ถ€ํ„ฐ ์‹œ์ž‘, ๋งˆ์ง€๋ง‰ ์นธ์—๋Š” 1๋กœ ๊ณฑํ•˜๊ธฐ ๋“ฑ์˜ ๋ฐฉ๋ฒ•๋„ ์ถฉ๋ถ„ํžˆ ์œ ํšจํ•˜๋‹ค๊ณ  ๋ด…๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๊ณ  ๋ณด๋‹ˆ, ์ด๋ฏธ 1๋กœ fill์ด ๋˜์—ˆ๋Š”๋ฐ ๋˜ resultArr[0] = 1๋กœ ์ดˆ๊ธฐํ™”ํ•˜๊ณ  ์žˆ์—ˆ๋„ค์š”.
์ด ๋ถ€๋ถ„ ์กฐ๊ธˆ ๋” ๋‹ค๋“ฌ์–ด ๋ณผ ์—ฌ์ง€๊ฐ€ ์žˆ๊ฒ ์–ด์š”.

@novacat25 novacat25 Nov 19, 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.

์ œ์•ˆ ์ฃผ์‹  ๋ถ€๋ถ„,์—ฌ๋Ÿฌ๋ชจ๋กœ ๊ฒ€ํ† ํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค๋งŒ ์—ญ์‹œ continue๋กœ ๋ถˆํ•„์š”ํ•œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๊ฐ€ ๋“ค์–ด๊ฐ€ ์žˆ๋Š” ๊ฒƒ ๊ฐ™์•„ ์•„์˜ˆ ๋œฏ์–ด๊ณ ์ณค์Šต๋‹ˆ๋‹ค..ใ…‹ใ…‹

  const lastIdx = nums.length - 1

  for (let i = 1; i <= lastIdx; i++) {
    leftProductedVal *= nums[i - 1]
    resultArr[i] = leftProductedVal
  }

  for (let i = lastIdx - 1; i >= 0; i--) {
    rightProductedVal *= nums[i + 1]
    resultArr[i] *= rightProductedVal
  }

์ œ๊ฐ€ ์“ด ์ฝ”๋“œ ๋ง๊ณ  ๋ฐฐ์—ด์„ ์“ฐ๋Š” ๋‹ค๋ฅธ ์ฝ”๋“œ๋“ค๋„ ์ญ‰ ํ›‘์–ด ๋ณด์•˜๋Š”๋ฐ... START_IDX๋‚˜ MAX_INDEX์ฒ˜๋Ÿผ ๋ฐฐ์—ด ์ธ๋ฑ์Šค์— ์ƒ์ˆ˜ ์ฒ˜๋ฆฌ๊ฐ€ ๋งž๋‚˜? ๋Š” ์˜๋ฌธ์ด ๋“ค๋”๋ผ๊ณ ์š”.
๊ด€๋ก€ ์ƒ์œผ๋กœ ๋ณด์•„๋„ const PI = 3.14 ๊ฐ™์ด ๊ฐ’์ด ์ผ๊ด€์ ์ธ ๊ฒฝ์šฐ๋ผ๋ฉด ๋ชจ๋ฅผ๊นŒ, ๋ฐฐ์—ด ์ธ๋ฑ์Šค ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š” ์ผ๋ฐ˜์ ์ธ camelCase ๋ณ€์ˆ˜๋กœ ๋‘๋Š” ๊ฒŒ ๋” ๋‚˜์•„ ๋ณด์ด๋”๋ผ๊ณ ์š”.

๋”ฐ๋ผ์„œ, ์‹œ์ž‘ ๋ถ€๋ถ„์€ 0์œผ๋กœ ์ฒ˜๋ฆฌ, ๋ฐฐ์—ด top ๋ถ€๋ถ„์€ lastIdx๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค!

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.

์–ธ์–ด๋ณ„๋กœ๋„ ๋ณ€์ˆ˜๋ช… ๊ด€๋ก€๊ฐ€ ์ƒ์ดํ•œ ๊ฒƒ ๊ฐ™๋„ค์š”..
์ €๋Š” ์ฃผ๋กœ lowercase๋กœ๋งŒ ๋ณ€์ˆ˜๋ช…์„ ์ž‘์„ฑํ•˜๋Š”๋ฐ ๊ณต๋ถ€ํ•˜๋ฉด ํ• ์ˆ˜๋ก ์ƒˆ๋กญ๋„ค์š” ใ…Žใ…Ž
continue๋ฅผ ์ œ์™ธํ•˜๊ณ  ๋ฐ˜๋ณต ๋ฒ”์œ„๋กœ ์ฒ˜๋ฆฌํ•˜๋‹ˆ ๋” ๊น”๋”ํ•ด์ง„ ๊ฒƒ ๊ฐ™๋„ค์š”
์ €๋Š” continue ์“ธ ์ƒ๊ฐ์€ ๋ชปํ–ˆ์–ด์„œ ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ธด๊ฑด๋ฐ ๋•๋ถ„์— ๋˜ ๋‹ค๋ฅธ ํ’€์ด๊ฐ€ ๋‚˜์˜จ ๊ฒƒ ๊ฐ™์•„ ๋ฐฐ์›Œ๊ฐ‘๋‹ˆ๋‹ค๐Ÿ™‚

Comment on lines +25 to +26
leftProductedVal *= nums[i - 1]
resultArr[i] = leftProductedVal

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.

์ €๋Š” answer[i - 1]์— nums[i - 1]์„ ๊ณฑํ•ด answer[i]์— ์ €์žฅํ•˜๋Š” ์‹์œผ๋กœ ํ–ˆ๋Š”๋ฐ, leftProductedVal ๋ณ€์ˆ˜์— ๋”ฐ๋กœ ๋ˆ„์ ํ•˜๋‹ˆ ๋” ๋ช…์‹œ์ ์ธ ๊ฒƒ ๊ฐ™๋„ค์š”..! ํ’€์ด๊ฐ€ ๋น„์Šทํ•˜๋ฉด์„œ๋„ ์ •์˜๋ฐฉ์‹์ด ๋‹ฌ๋ผ ์ฝ”๋“œ ์ฝ๋Š” ์žฌ๋ฏธ๊ฐ€ ์žˆ๋„ค์š” ใ…Žใ…Ž
์ˆ˜๊ณ ํ•˜์…จ์Šต๋‹ˆ๋‹ค!

Comment thread 3sum/novacat25.ts
Comment on lines +33 to +34
while (j < k && nums[j] === nums[j - 1]) j++
while (j < k && nums[k] === nums[k + 1]) k--

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.

์ €๋Š” ์ค‘๋ณต ์ œ๊ฑฐ๋Š” set์œผ๋กœ ์„ค์ •!์ด๋ผ๋Š” ๋‚˜๋ฆ„ ์ €๋งŒ์˜ ๊ทœ์น™์„ ์ •ํ•ด๋‘๊ณ  ์ฝ”๋“œ๋ฅผ ์งœ๋Š”๋ฐ,
res๋ฅผ ์ผ๋ฐ˜ ๋ฐฐ์—ด๋กœ ๋‘๊ณ  ํƒ์ƒ‰ ๊ณผ์ •์—์„œ ์ค‘๋ณต๊ฐ’์„ ์ œ์™ธํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์‹œ๊ฐ„๋ณต์žก๋„๋Š” ๋น„์Šทํ•ด์„œ ๋ฌธ์ œํ’€์ด์˜ ํ๋ฆ„์„ ํŒŒ์•…ํ•˜๊ธฐ์— ๋” ์šฉ์ดํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ € ์ •๋‹ต์„ ์ฐพ์€ ๋’ค left, right๋ฅผ ํ•œ ์นธ์”ฉ๋งŒ ์ด๋™ํ•ด์„œ ์ค‘๋ณต ์กฐํ•ฉ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด ๋ถ€๋ถ„์—์„œ ๊ฐ™์€ ๊ฐ’์„ ๊ฑด๋„ˆ๋›ฐ๋ฉด ๊ตณ์ด set์„ ์“ฐ์ง€ ์•Š์•„๋„ ๋  ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ™‚

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.

๋„ค, ํƒ์ƒ‰ ์ค‘์— ์ค‘๋ณต์„ ์•„์˜ˆ ์น˜์›Œ๋ฒ„๋ฆฌ๋ฉด ๋‚˜์ค‘์— tuple์ด๋‚˜ set ๋“ฑ์˜ ์ฒ˜๋ฆฌ๊ฐ€ ๋“ค์–ด๊ฐ€์ง€ ์•Š์•„๋„ ๊ทธ๋งŒํผ ์ด๋“์ด๊ธด ํ•˜๋‹ˆ๊นŒ์š”!

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.

์ด๋ฒˆ์— ๋ฐฑ์ค€ ์žฌ์˜คํ”ˆํ•œ๊น€์— https://acmicpc.net/problem/3273
ํˆฌ ํฌ์ธํ„ฐ ๊ธฐ๋ฒ•์œผ๋กœ ๋‹ค์‹œ ํ’€์–ด๋ดค๋Š”๋ฐ, leetcode๋ฌธ์ œ๋ณด๋‹ค๋Š” ๋‘ ํ•ฉ์ด๋ผ์„œ ๋” ๋‚œ์ด๋„๋Š” ์‰ฝ์ง€๋งŒ
ํ™•์‹คํžˆ ์ ์šฉ๋ฐฉ๋ฒ•์„ ์•Œ๊ฒŒ๋˜์–ด์„œ ์ข‹๋„ค์š”~!
๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค:)

Comment on lines +11 to +13
const BASE_CHAR_CODE = "a".charCodeAt(0)

const getCodeIndex = (code: number) => code - BASE_CHAR_CODE

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.

์ฒ˜์Œ์—๋Š” ์ •๋ ฌ์ด๋‚˜ Map ๋“ฑ์„ ์ƒ๊ฐํ–ˆ๋Š”๋ฐ,
๋ฌธ์ œ ์กฐ๊ฑด์œผ๋กœ ํžŒํŠธ๋ฅผ ๋ณด๊ณ  ๋‚˜์„œ ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์ด ์žˆ๋”๋ผ๊ณ ์š”..!
์ €๋„ ๊ทธ๋ž˜์„œ ๊ณต๊ฐ„ ๋ณต์žก๋„๋ฅผ ์ด๋ ‡๊ฒŒ ์•„๋‚„ ์ˆ˜ ์žˆ์—ˆ๊ตฌ๋‚˜..ํ•˜๊ณ  ๋ฐฐ์› ์Šต๋‹ˆ๋‹ค.

Comment on lines +18 to +23

const dfs = (node: TreeNode | null, low: number, high: number): boolean => {
if (!node) return true // Null์ธ Node๋Š” BST ์กฐ๊ฑด์„ ๋งŒ์กฑํ•œ๋‹ค๊ณ  ๊ฐ„์ฃผํ•ด ์žฌ๊ท€์ ์œผ๋กœ True๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
if (!(low < node.val && node.val < high)) return false // ํ˜„์žฌ Node์˜ ๊ฐ’์ด ํ—ˆ์šฉ ๋ฒ”์œ„์— ์†ํ•˜์ง€ ์•Š์œผ๋ฉด False๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
return dfs(node.left, low, node.val) && dfs(node.right, node.val, high) // ์™ผ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ์™€ ์˜ค๋ฅธ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ํ™•์ธํ•˜๋ฉฐ, ํ—ˆ์šฉ ๋ฒ”์œ„๋ฅผ ๊ฐฑ์‹ ํ•œ๋‹ค.
}

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.

ํ’€๋ฉด์„œ๋„ ์ด ๋ฌธ์ œ๋Š” ํ’€์ด๊ฐ€ ์ •๋ง ๋‹ค์–‘ํ•  ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐ์ด ๋“ค์—ˆ๋Š”๋ฐ์š”
์ €๋Š” ์ด ๋ฌธ์ œ ๊ต‰์žฅํžˆ ๊ณ ์ „ํ•˜๋ฉด์„œ ํ’€์—ˆ์–ด์„œ ๋‹ค๋ฅธ ๋ถ„๋“ค ํ’€์ด๋ฅผ ๋ณด๊ณ  ๋งŽ์ด ๋ฐฐ์›Œ๊ฐ€๊ณ  ์‹ถ์—ˆ๋„ค์š” ใ…Žใ…Ž
์ €๋Š” ์ค‘์œ„์ˆœํšŒ๋กœ ํ’€์—ˆ๋Š”๋ฐ left--> ์ž์‹  ๋…ธ๋“œ--> right์ด๋ ‡๊ฒŒ ํ•ด์„œ ๊ฐ’์ด ์˜ค๋ฆ„์ฐจ์ˆœ์ด ๋‚˜์˜ค๋Š”์ง€๋ฅผ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•˜์˜€๋Š”๋ฐ
low, high๋กœ ๋ฒ”์œ„๋ฅผ ๋‘๊ณ  ๋…ธ๋“œ๊ฐ’์˜ ํฌํ•จ๋ฒ”์œ„๋ฅผ ์ขํ˜€ ๋‚˜๊ฐ€๋Š” ๋ฐฉ์‹๋„ ๊ต‰์žฅํžˆ ๊น”๋”ํ•˜๋„ค์š”!

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.

๋„ค, left->Parent-> child, Parent์—์„œ left-child ์ „๊ฐœ ๋“ฑ ๊ฐ์ž ํ’€์ด ๋ฐฉ์‹์ด ์žˆ๋Š” ๊ฒƒ ๊ฐ™๋”๋ผ๊ณ ์š”..!
์ €๋Š” Parent์—์„œ๋„ left/right๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ๋ถˆ๋Ÿฌ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค.

}

const dfs = (node: TreeNode | null, low: number, high: number): boolean => {
if (!node) return true // Null์ธ Node๋Š” BST ์กฐ๊ฑด์„ ๋งŒ์กฑํ•œ๋‹ค๊ณ  ๊ฐ„์ฃผํ•ด ์žฌ๊ท€์ ์œผ๋กœ True๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

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.

!node๋กœ ๋นˆ ๋…ธ๋“œ๋Š” ๋ฐ”๋กœ ๊ฑด๋„ˆ๋›ฐ๋Š”๊ฑด์š”

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.

๋„ค! child๋กœ node.left / node.right๋ฅผ ๋ถ€๋ฅผ ๋•Œ, ์ € ์กฐ๊ฑด๋ฌธ์„ ์ถฉ์กฑ์‹œ์ผœ ๊ฒ€์‚ฌ๋ฅผ ์•„์˜ˆ ๋น ์ง‘๋‹ˆ๋‹ค.


const dfs = (node: TreeNode | null, low: number, high: number): boolean => {
if (!node) return true // Null์ธ Node๋Š” BST ์กฐ๊ฑด์„ ๋งŒ์กฑํ•œ๋‹ค๊ณ  ๊ฐ„์ฃผํ•ด ์žฌ๊ท€์ ์œผ๋กœ True๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
if (!(low < node.val && node.val < high)) return false // ํ˜„์žฌ Node์˜ ๊ฐ’์ด ํ—ˆ์šฉ ๋ฒ”์œ„์— ์†ํ•˜์ง€ ์•Š์œผ๋ฉด 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.

์งˆ๋ฌธ์ด ์žˆ์Šต๋‹ˆ๋‹ค..!
ํŒŒ์ด์ฌ์—์„œ๋Š” low < node.val < high์ฒ˜๋Ÿผ ๋ถ€๋“ฑ์‹์„ ํ•œ๋ฒˆ์— ์“ธ ์ˆ˜ ์žˆ๋Š”๋ฐ, TS์—์„œ๋Š” ์ด๋ ‡๊ฒŒ ์“ฐ๋ฉด ์•ˆ ๋˜๋Š” ๊ฑด๊ฐ€์š”?

@novacat25 novacat25 Nov 21, 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.

image ๋„ค, TS์—์„œ๋Š” ์ด๋ ‡๊ฒŒ ์˜ค๋ฅ˜๊ฐ€ ํ„ฐ์ง€๋Š” ๊ฒƒ ๊ฐ™๋”๋ผ๊ณ ์š”..! image ์ด๋ ‡๊ฒŒ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

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.

์˜ค ts์—์„œ๋Š” operator ์—ฐ์‚ฐ์ž๋ฅผ boolean๊ณผ number ์‚ฌ์ด์—๋Š” ์“ธ ์ˆ˜ ์—†๋‹ค๋Š” ๋‚ด์šฉ ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ณ ๊ฐ‘๋‹ˆ๋‹ค!
๋”๋ถˆ์–ด ํŒŒ์ด์ฌ์˜ and ๋Œ€์‹  &&๋กœ ์“ฐ๋Š” ํ‘œ๊ธฐ๋ฒ•๋„ ๋ฐฐ์šฐ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค~

}
}

const dfs = (node: TreeNode | null, low: number, high: number): boolean => {

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.

ts์—์„œ๋Š” ๋ฐ˜ํ™˜ํƒ€์ž… (์—ฌ๊ธฐ์„œ๋Š” boolean)์„ ํ•ญ์ƒ ๋ช…์‹œํ•ด์ค˜์•ผํ•˜๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค..!
์ด ๋ฌธ์ œ์—์„œ๋Š” dfs ํ•จ์ˆ˜๊ฐ€ true/false๋ฅผ returnํ•ด์„œ boolean์„ ๋”ฐ๋กœ ์จ ์ฃผ์‹  ๊ฑด์ง€ ๊ถ๊ธˆํ–ˆ์Šต๋‹ˆ๋‹ค ๐Ÿ™‚

@novacat25 novacat25 Nov 21, 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.

๋ณดํ†ต์€ TS์—์„œ return value ๊ฐ’์„ ๋ณด๊ณ  ์ถ”๋ก ์„ ํ•ด ์ฃผ๊ธฐ ๋•Œ๋ฌธ์— ์ƒ๋žตํ•ด๋„ ๋ฌธ์ œ๋Š” ์—†์Šต๋‹ˆ๋‹ค.
ํƒ€์ž… ์ถ”๋ก ์ด ํ™•์‹คํ•˜๊ณ  ์ฝ”๋“œ๋กœ ์•Œ์•„์ฑŒ ์ˆ˜ ์žˆ๋‹ค๋ฉด ์—†๋Š” ๊ฒŒ ๋‚˜์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ,

(๋‚˜์œ ์˜ˆ์‹œ)

const name = "John"
const age = 20
const names = ["John", "Terry"]

TypeScript๊ฐ€ ์ผ๋ฐ˜์ ์œผ๋กœ ์ถ”๋ก ํ•˜๊ธฐ ํž˜๋“  ๊ฒฝ์šฐ(Generic, API response ๋“ฑ)๊ฑฐ๋‚˜

const users: User[] = []
const [users, setUsers] = useState<User[]>([])

ํƒ€์ž…์ด ์ฝ”๋“œ์˜ ์„ค๊ณ„ ์˜๋„๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค๋ฉด

type UserStatus = "active" | "inactive" | "pending"

const getUserStatus = (user: User): UserStatus => {
  // ๋ณต์žกํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง
}

์ด๋Ÿฐ ์‹์œผ๋กœ ๋ช…์‹œํ•ด์ฃผ๋Š” ๊ฒŒ ์ข‹๋‹ค๊ณ  ํ•˜๋„ค์š”.

ํ•˜์ง€๋งŒ, ์ด๋ฒˆ dfs ์ฝ”๋“œ ๊ฐ™์€ ๊ฒฝ์šฐ์—๋Š” ์žฌ๊ท€ํ•จ์ˆ˜๊ฐ€ ๋ถˆ๋Ÿฌ์ ธ ์žˆ๋Š” ์ด์œ ์ธ์ง€ ์ž๋ ฅ์œผ๋กœ Type Check๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•œ ์ƒํ™ฉ์ด์—ˆ์œผ๋ฉฐ,
ํƒ€์ž… ๋ช…์‹œ๋ฅผ ํ†ตํ•ด ๋ถ„๋ช…ํ•˜๊ฒŒ ํ•ด์ค˜์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

const dfs = (node: TreeNode | null, low: number, high: number) => {
  if (!node) return true // Null์ธ Node๋Š” BST ์กฐ๊ฑด์„ ๋งŒ์กฑํ•œ๋‹ค๊ณ  ๊ฐ„์ฃผํ•ด ์žฌ๊ท€์ ์œผ๋กœ True๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  if (!(low < node.val && node.val < high)) return false // ํ˜„์žฌ Node์˜ ๊ฐ’์ด ํ—ˆ์šฉ ๋ฒ”์œ„์— ์†ํ•˜์ง€ ์•Š์œผ๋ฉด False๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  return dfs(node.left, low, node.val) && dfs(node.right, node.val, high) // ์™ผ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ์™€ ์˜ค๋ฅธ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ๋ฅผ ์žฌ๊ท€์ ์œผ๋กœ ํ™•์ธํ•˜๋ฉฐ, ํ—ˆ์šฉ ๋ฒ”์œ„๋ฅผ ๊ฐฑ์‹ ํ•œ๋‹ค.
}

'dfs' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

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.

์ƒ์„ธํ•œ ์˜ˆ์‹œ๊นŒ์ง€ ๋“ค์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค
์ถ”๋ก ์ด ํ™•์‹คํ•œ ๊ฒฝ์šฐ์—” ์ƒ๋žตํ•˜๋Š” ๊ฒŒ ๋” ๊น”๋”ํ•˜๊ณ , ๋ฐ˜๋Œ€์˜ ์ผ€์ด์Šค๋‚˜ ํƒ€์ž…์ด ์„ค๊ณ„ ์˜๋„๋ฅผ ๋“œ๋Ÿฌ๋‚ผ ๋•Œ๋Š” ๋ช…์‹œํ•˜๋Š” ๊ฒŒ ์ข‹๊ตฐ์š”
dfs์ฒ˜๋Ÿผ ๋ฐ˜ํ™˜์‹์—์„œ ์ž๊ธฐ ์ž์‹ ์„ ํ˜ธ์ถœํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ์žฌ๊ท€ ํ•จ์ˆ˜๋Š” ๋ฐ˜ํ™˜ ํƒ€์ž…์„ ๋ช…์‹œํ•ด ์ค˜์•ผ ํ•œ๋‹ค๋Š” ์ ๋„ ์•Œ๊ณ  ๊ฐ‘๋‹ˆ๋‹ค!

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