////
Search
Duplicate
πŸ“ƒ

λ…ˆ & blackraven

Created
2022/02/14 12:44
Tags
속성

문제 (~22:05)

ν”Όλ³΄λ‚˜μΉ˜ μˆ˜λŠ” F(0) = 0, F(1) = 1일 λ•Œ, 2 μ΄μƒμ˜ n에 λŒ€ν•˜μ—¬ F(n) = F(n-1) + F(n-2) κ°€ μ μš©λ˜λŠ” μ ν™”μ‹μž…λ‹ˆλ‹€. 2 μ΄μƒμ˜ n이 μž…λ ₯λ˜μ—ˆμ„ λ•Œ, fibonacci ν•¨μˆ˜λ₯Ό μ œμž‘ν•˜μ—¬ n번째 ν”Όλ³΄λ‚˜μΉ˜ 수λ₯Ό λ°˜ν™˜ν•΄ μ£Όμ„Έμš”. 예λ₯Ό λ“€μ–΄ n = 3이라면 2λ₯Ό λ°˜ν™˜ν•΄μ£Όλ©΄ λ©λ‹ˆλ‹€.
ex_ F(4)인 경우 0 1 1 2 '3' μ΄λ―€λ‘œ F(4) = 3 μž…λ‹ˆλ‹€.
Plain Text
볡사
function fibonacci(number) { if (number <= 1) { return number } return fibonacci(number - 1) + fibonacci(number - 2) } console.log(fibonacci(4))
JavaScript
볡사

문제2

waterMelonν•¨μˆ˜λŠ” μ •μˆ˜ n을 λ§€κ°œλ³€μˆ˜λ‘œ μž…λ ₯λ°›μŠ΅λ‹ˆλ‹€.
길이가 n이고, μˆ˜λ°•μˆ˜λ°•μˆ˜β€¦μ™€ 같은 νŒ¨ν„΄μ„ μœ μ§€ν•˜λŠ” λ¬Έμžμ—΄μ„ λ¦¬ν„΄ν•˜λ„λ‘ ν•¨μˆ˜λ₯Ό μ™„μ„±ν•˜μ„Έμš”.
ex_ waterMelon(4)이 4이면 β€˜μˆ˜λ°•μˆ˜λ°•β€™μ„ λ¦¬ν„΄ν•˜κ³  waterMelon(3)이라면 β€˜μˆ˜λ°•μˆ˜β€™λ₯Ό λ¦¬ν„΄ν•˜λ©΄ λ©λ‹ˆλ‹€.
Plain Text
볡사
function waterMelon(n){ let multipliedWaterMelon = "μˆ˜λ°•".repeat(parseInt(n/2)) return n % 2 ? multipliedWaterMelon + "수" : multipliedWaterMelon }
JavaScript
볡사
function waterMelon(n){ }
Plain Text
볡사