Skip to content

Commit

Permalink
fix(C): fix the array initialization in coin_change.c (#1277)
Browse files Browse the repository at this point in the history
* add

* Update coin_change.c

* Update coin_change.c

---------

Co-authored-by: Yudong Jin <[email protected]>
  • Loading branch information
qq909244296 and krahets committed Apr 14, 2024
1 parent 4d9bbe7 commit 16942df
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion codes/c/chapter_dynamic_programming/coin_change.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down

0 comments on commit 16942df

Please sign in to comment.