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:
jiawenshi 2024-04-14 17:30:21 +08:00 committed by GitHub
parent 4d9bbe72e1
commit 16942dfe32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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++) {