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 44a685f commit 5114d8cCopy full SHA for 5114d8c
Coin Change/Coin_Change.cpp
@@ -0,0 +1,28 @@
1
+// 典型的动态规划
2
+// Runtime: 36 ms, faster than 88.91% of C++ online submissions for Coin Change.
3
+// Memory Usage: 12.6 MB, less than 86.27% of C++ online submissions for Coin Change.
4
+class Solution
5
+{
6
+public:
7
+ int coinChange(vector<int>& coins, int amount)
8
+ {
9
+ vector<int> memo(amount + 1, 0);
10
+ for (int i = 1; i <= amount; ++i)
11
12
+ int minValue = INT_MAX;
13
+ bool found = false;
14
+ for (int coin : coins)
15
16
+ if (i - coin < 0 || memo[i - coin] == -1)
17
+ continue;
18
+ else
19
20
+ minValue = min(minValue, memo[i - coin] + 1);
21
+ found = true;
22
+ }
23
24
+ memo[i] = found ? minValue : -1;
25
26
+ return memo[amount];
27
28
+};
0 commit comments