mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-11 15:06:07 +00:00
build
This commit is contained in:
@@ -297,7 +297,7 @@ comments: true
|
||||
}
|
||||
// 2. 统计各数字的出现次数
|
||||
// counter[num] 代表 num 的出现次数
|
||||
int *counter = malloc(sizeof(int) * m);
|
||||
int *counter = calloc(m, sizeof(int));
|
||||
for (int i = 0; i < size; i++) {
|
||||
counter[nums[i]]++;
|
||||
}
|
||||
@@ -308,6 +308,8 @@ comments: true
|
||||
nums[i] = num;
|
||||
}
|
||||
}
|
||||
// 4. 释放内存
|
||||
free(counter);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -744,7 +746,7 @@ $$
|
||||
}
|
||||
// 2. 统计各数字的出现次数
|
||||
// counter[num] 代表 num 的出现次数
|
||||
int *counter = malloc(sizeof(int) * m);
|
||||
int *counter = calloc(m, sizeof(int));
|
||||
for (int i = 0; i < size; i++) {
|
||||
counter[nums[i]]++;
|
||||
}
|
||||
@@ -763,6 +765,8 @@ $$
|
||||
}
|
||||
// 使用结果数组 res 覆盖原数组 nums
|
||||
memcpy(nums, res, size * sizeof(int));
|
||||
// 5. 释放内存
|
||||
free(counter);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user