This commit is contained in:
krahets
2023-04-18 21:18:58 +08:00
parent 363f1f4b5f
commit 98812b1974
2 changed files with 33 additions and 1 deletions

View File

@@ -949,6 +949,13 @@ $$
=== "C"
```c title="space_complexity.c"
/* 哈希表 */
struct hashTable {
int key;
int val;
UT_hash_handle hh; // 基于 uthash.h 实现
};
/* 线性阶 */
void linear(int n) {
// 长度为 n 的数组占用 O(n) 空间
@@ -968,7 +975,6 @@ $$
// 长度为 n 的哈希表占用 O(n) 空间
hashTable *h = NULL;
for (int i = 0; i < n; i++) {
hashTable *tmp = malloc(sizeof(hashTable));
tmp->key = i;