mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 09:46:29 +08:00
fix(C): fix the array initialization in coin_change.c (#1277)
* add * Update coin_change.c * Update coin_change.c --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
parent
4d9bbe72e1
commit
16942dfe32
1 changed files with 5 additions and 1 deletions
|
@ -50,8 +50,12 @@ int coinChangeDPComp(int coins[], int amt, int coinsSize) {
|
|||
int n = coinsSize;
|
||||
int MAX = amt + 1;
|
||||
// 初始化 dp 表
|
||||
int *dp = calloc(amt + 1, sizeof(int));
|
||||
int *dp = malloc((amt + 1) * sizeof(int));
|
||||
for (int j = 1; j <= amt; j++) {
|
||||
dp[j] = MAX;
|
||||
}
|
||||
dp[0] = 0;
|
||||
|
||||
// 状态转移
|
||||
for (int i = 1; i <= n; i++) {
|
||||
for (int a = 1; a <= amt; a++) {
|
||||
|
|
Loading…
Reference in a new issue