Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a80eeae

Browse filesBrowse files
authored
Create 11 coinChange.cpp
1 parent 827e2dd commit a80eeae
Copy full SHA for a80eeae

File tree

Expand file treeCollapse file tree

1 file changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.