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 c5df935 commit 03671deCopy full SHA for 03671de
1 file changed
coin-change/Yiseull.java
@@ -0,0 +1,20 @@
1
+class Solution {
2
+
3
+ private int answer = Integer.MAX_VALUE;
4
5
+ public int coinChange(int[] coins, int amount) {
6
+ int[] dp = new int[amount + 1];
7
+ Arrays.fill(dp, amount + 1);
8
+ dp[0] = 0;
9
10
+ for (int i = 1; i < amount + 1; i++) {
11
+ for (int coin : coins) {
12
+ if (coin <= i) {
13
+ dp[i] = Math.min(dp[i], dp[i - coin] + 1);
14
+ }
15
16
17
18
+ return dp[amount] > amount ? -1 : dp[amount];
19
20
+}
0 commit comments