Skip to content

Commit 771158f

Browse files
add: Coin Change
1 parent f3dc504 commit 771158f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.Arrays;
2+
3+
class Solution {
4+
public int coinChange(int[] coins, int amount) {
5+
int[] memo = new int[amount + 1];
6+
Arrays.fill(memo, amount + 1); // 도달 λΆˆκ°€λŠ₯ν•œ μ΄ˆκΈ°κ°’
7+
memo[0] = 0; // 0원을 λ§Œλ“€κΈ° μœ„ν•œ 동전 μˆ˜λŠ” 0개
8+
9+
for (int coin : coins) {
10+
for (int i = coin; i <= amount; i++) {
11+
memo[i] = Math.min(memo[i], memo[i - coin] + 1);
12+
}
13+
}
14+
15+
return memo[amount] > amount ? -1 : memo[amount];
16+
}
17+
}

β€Žword-search/YoungSeok-Choi.javaβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ public void dfs(char[][] b, int x, int y) {
117117
dfs(b, nx, ny);
118118
}
119119
}
120-
}}
120+
}}

0 commit comments

Comments
Β (0)