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 f625aac commit 69b7a79Copy full SHA for 69b7a79
coin-change/minji-go.java
@@ -0,0 +1,23 @@
1
+/*
2
+ Problem: https://leetcode.com/problems/coin-change/
3
+ Description: return the fewest number of coins that you need to make up that amount
4
+ Concept: Array, Dynamic Programming, Breadth-First Search
5
+ Time Complexity: O(N²), Runtime 15ms - N is the amount
6
+ Space Complexity: O(N), Memory 44.28MB
7
+*/
8
+class Solution {
9
+ public int coinChange(int[] coins, int amount) {
10
+ int[] dp = new int[amount+1];
11
+ Arrays.fill(dp, amount+1);
12
+ dp[0]=0;
13
+
14
+ for(int i=1; i<=amount; i++){
15
+ for(int coin : coins){
16
+ if(i >= coin) {
17
+ dp[i] = Math.min(dp[i], dp[i-coin] +1);
18
+ }
19
20
21
+ return dp[amount]>amount? -1: dp[amount];
22
23
+}
0 commit comments