We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8dbd72d commit 6cd9569Copy full SHA for 6cd9569
coin-change/jinhyungrhee.java
@@ -0,0 +1,22 @@
1
+import java.util.*;
2
+class Solution {
3
+ int INF = 987654321;
4
+ public int coinChange(int[] coins, int amount) {
5
+ if (amount == 0) return 0;
6
+
7
+ int[] dp = new int[amount + 1];
8
+ Arrays.fill(dp, INF);
9
10
+ dp[0] = 0;
11
+ for (int coin : coins) {
12
+ if (coin <= amount) dp[coin] = 1;
13
+ }
14
15
+ for (int i = 1; i <= amount; i++) {
16
17
+ if ((i - coin) >= 0) dp[i] = Math.min(dp[i], dp[i - coin] + 1);
18
19
20
+ return (dp[amount] == INF) ? -1 : dp[amount];
21
22
+}
0 commit comments