File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Arrays ;
2+
3+ class Solution {
4+ //νμ΄ μ리 = νΉμ κΈμ‘μ λ§λ€ λ μ΅μ λμ μλ λͺ κ°?
5+ //μ) 0μμ λμ 0κ°
6+ // 1μμ λμ 1κ°
7+ // 2μμ λμ 1
8+ public int coinChange (int [] coins , int amount ) {
9+ //λΆκ°λ₯ν κ°
10+ int max = amount + 1 ;
11+ int [] dp = new int [amount + 1 ];
12+ //μ΅μ λμ μλ₯Ό λͺ¨λ λΆκ°λ₯ν κ°μΌλ‘ μ€μ
13+ Arrays .fill (dp , max );
14+ dp [0 ] = 0 ;
15+
16+ //κΈμ‘ 1μ λΆν° κ³μ°
17+ for (int i = 1 ; i <= amount ; i ++) {
18+ //μ¬μ©ν μ μλ λμ μ κΊΌλ
19+ for (int coin : coins ) {
20+ if (coin <= i ) {
21+ dp [i ] = Math .min (dp [i ], dp [i - coin ] + 1 );
22+ }
23+ }
24+ }
25+
26+ return dp [amount ] > amount ? -1 : dp [amount ];
27+ }
28+ }
You canβt perform that action at this time.
0 commit comments