Skip to content

Commit f96fa50

Browse files
committed
Coin Chage solution
1 parent 03c9620 commit f96fa50

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

coin-change/PDKhan.cpp

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

0 commit comments

Comments
 (0)