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 1d3dba3 commit a3f1354Copy full SHA for a3f1354
algorithms/cpp/coinChange/coinChange.cpp
@@ -1,5 +1,5 @@
1
// Source : https://leetcode.com/problems/coin-change/
2
-// Author : Calinescu Valentin
+// Author : Calinescu Valentin, Hao Chen
3
// Date : 2015-12-28
4
5
/***************************************************************************************
@@ -60,3 +60,24 @@ class Solution {
60
return -1;
61
}
62
};
63
+
64
65
+//Another DP implmentation, same idea above
66
+class Solution {
67
+public:
68
+ int coinChange(vector<int>& coins, int amount) {
69
+ const int MAX = amount +1;
70
+ vector<int> dp(amount+1, MAX);
71
+ dp[0]=0;
72
73
+ for(int i=1; i<=amount; i++) {
74
+ for (int j=0; j<coins.size(); j++){
75
+ if (i >= coins[j]) {
76
+ dp[i] = min( dp[i], dp[i-coins[j]] + 1 );
77
+ }
78
79
80
81
+ return dp[amount]==MAX ? -1 : dp[amount];
82
83
+};
0 commit comments