Skip to content

Commit 04b6ac1

Browse files
committed
June 7 ques
1 parent 3e9d99b commit 04b6ac1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//https://leetcode.com/explore/challenge/card/june-leetcoding-challenge/539/week-1-june-1st-june-7th/3353/
2+
3+
4+
5+
class Solution {
6+
public:
7+
int change(int amount, vector<int>& coins) {
8+
vector<vector<int>> DP(amount + 1, vector<int>(coins.size() + 1, 0));
9+
sort(coins.begin(), coins.end());
10+
11+
12+
int i, j;
13+
for(i = 0; i <= coins.size(); i++)
14+
DP[0][i] = 1;
15+
16+
for(i = 1; i <= amount; i++) {
17+
for(j = 1; j <= coins.size(); j++) {
18+
if(i >= coins[j - 1])
19+
DP[i][j] = DP[i - coins[j - 1]][j];
20+
DP[i][j] += DP[i][j - 1];
21+
}
22+
}
23+
return DP[amount][coins.size()];
24+
}
25+
};

0 commit comments

Comments
 (0)