Skip to content

Commit c853065

Browse files
authored
Merge pull request #247 from angie1015/patch-1
Create 322.cpp
2 parents 20081b2 + b208c90 commit c853065

File tree

1 file changed

+19
-0
lines changed
  • leetcode/cpp/dynamic programming

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Coin change
2+
3+
class Solution {
4+
public:
5+
int coinChange(vector<int>& coins, int amount) {
6+
vector<int> dp(amount+1, INT_MAX-1);
7+
dp[0] = 0;
8+
9+
for(auto c : coins){
10+
for(int x = c; x<=amount; x++){
11+
dp[x] = min(dp[x], dp[x-c]+1);
12+
}
13+
}
14+
if(dp[amount]==INT_MAX-1){
15+
return -1;
16+
}
17+
return dp[amount];
18+
}
19+
};

0 commit comments

Comments
 (0)