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>
pull/1278/head
jiawenshi 7 months ago committed by GitHub
parent 4d9bbe72e1
commit 16942dfe32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -50,8 +50,12 @@ int coinChangeDPComp(int coins[], int amt, int coinsSize) {
int n = coinsSize; int n = coinsSize;
int MAX = amt + 1; int MAX = amt + 1;
// 初始化 dp 表 // 初始化 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; dp[0] = 0;
// 状态转移 // 状态转移
for (int i = 1; i <= n; i++) { for (int i = 1; i <= n; i++) {
for (int a = 1; a <= amt; a++) { for (int a = 1; a <= amt; a++) {

Loading…
Cancel
Save