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 66b2ff2 commit daf037dCopy full SHA for daf037d
coin-change/TonyKim9401.java
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public int coinChange(int[] coins, int amount) {
3
+ // TC: O(amount*n)
4
+ // SC: O(amount)
5
+ int[] dp = new int[amount + 1];
6
+ Arrays.fill(dp, amount + 1);
7
+
8
+ dp[0] = 0;
9
10
+ for (int i = 1; i <= amount; i++) {
11
+ for (int j = 0; j < coins.length; j++) {
12
+ if (i - coins[j] >= 0) {
13
+ dp[i] = Math.min(dp[i], 1 + dp[i - coins[j]]);
14
+ }
15
16
17
+ return dp[amount] != amount + 1 ? dp[amount] : -1;
18
19
+}
0 commit comments