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 115d330 commit 43580ccCopy full SHA for 43580cc
C++/coin-change.cpp
@@ -5,17 +5,17 @@
5
class Solution {
6
public:
7
int coinChange(vector<int>& coins, int amount) {
8
- vector<int> amounts(amount + 1, numeric_limits<int>::max());
9
- amounts[0] = 0;
+ vector<int> dp(amount + 1, numeric_limits<int>::max());
+ dp[0] = 0;
10
for (int i = 0; i <= amount; ++i) {
11
- if (amounts[i] != numeric_limits<int>::max()) {
+ if (dp[i] != numeric_limits<int>::max()) {
12
for (const auto& coin : coins) {
13
if (coin <= numeric_limits<int>::max() - i && i + coin <= amount) {
14
- amounts[i + coin] = min(amounts[i + coin], amounts[i] + 1);
+ dp[i + coin] = min(dp[i + coin], dp[i] + 1);
15
}
16
17
18
19
- return amounts[amount] == numeric_limits<int>::max() ? -1 : amounts[amount];
+ return dp[amount] == numeric_limits<int>::max() ? -1 : dp[amount];
20
21
};
0 commit comments