Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π λ¬Έμ λ§ν¬
Filling Bookcase Shelves
βοΈ μμλ μκ°
12μκ°
β¨ μλ μ½λ
λ¬Έμ μ€λͺ
μ λ ₯μΌλ‘ μ£Όμ΄μ§ books 2μ°¨μ λ°°μ΄μ μμλ 첫 λ²μ§Έ μμλ‘ λλΉλ₯Ό, λ λ²μ§Έ μμλ‘ λμ΄λ₯Ό μ§λλ€.
μμλλ‘ μ± μ μ λ°μ λλ κ° μ λ°μ λμ΄λ μ± μ μ λ ₯μΌλ‘ μ£Όμ΄μ§
shelfWidth
λ³΄λ€ μκ±°λ κ°μμΌ λμ μ μλ€.κ·Έλ κ² ν΄μ λ°°μΉλ₯Ό νμμ λ μ΅μμ λμ΄λ₯Ό ꡬνλΌ.
μ κ·Ό λ°©μ
μμλλ‘ μ°¨κ³‘μ°¨κ³‘ dpλ°°μ΄
heightArr
μ λ£μ΄μ£Όλ νμ¬ κ°μμ μ΄μ κ°λ€μ dpλ°°μ΄ μμμ λ°©λ¬Έν΄μ€λ€.μ¦ λΉκ΅ λ°©μμ μλμ κ°μ΄ μ΄λ£¨μ΄μ§λ€.
i-1
λ²μ§Έ μμμ μ΅μ λμ΄ κ°μ μ μ₯νλheightArr[i]
μλ€κ° μ΄μ μ μ΅μ κ°heightArr[i-1]
κ³Ό νμ¬ μμi-1
μ λμ΄λ₯Ό λν κ°μΌλ‘ μ΄κΈ°ν ν΄μ€λ€.i-2
λ²μ§Έ μμλΆν° 0λ²μ§Έ μμκΉμ§ λΉκ΅ν΄ μ€ κ²μ΄λ€.i-1
λ²μ§Έ λλΉμj-1
λ²μ§Έ μμμ λλΉλ₯Ό ν©νμ λshelfWidth
λ³΄λ€ ν¬λ©΄ λ°λ‘ λΉκ΅λ₯Ό μ’ λ£ν΄μ€λ€.j-1
λ²μ§Έ μμμ λμ΄μ νμ¬ μ΅λ λμ΄λ₯Ό μ§λκ³ μλ λ³μheight
κ°μ κ°±μ ν΄μ€λ€. μ¦, κ°μ μ λ°μ μμΉν κ²½μ° λμheight
μ κ°μΌλ‘ λ°λλ©΄μ ν΄λΉ μ λ°μ΄ μ°¨μ§νλ λμ΄λ₯Ό κ°λ¦¬ν€κ² λλ€.heightArr[i]
), μλλ©΄ κ°κΈ° λ€λ₯Έ μ λ°μΌλ‘ λΆλ₯νλκ² μ΅μμΈμ§(heightArr[j-1]
+height
) λΉκ΅ν΄μ€λ€.νκΈ°
λ¬Έμ λ₯Ό μ΄ν΄νλλ° μ΄λ €μμ κ²ͺμλ€...
π μλ‘κ² μκ²λ λ΄μ©