From 7351ec70a6347cbd5aa64d367405333f85180d5f Mon Sep 17 00:00:00 2001 From: krahets Date: Wed, 26 Jul 2023 15:34:46 +0800 Subject: [PATCH] build --- chapter_appendix/contribution.md | 2 +- chapter_array_and_linkedlist/array.md | 28 ++--- chapter_array_and_linkedlist/linked_list.md | 28 ++--- chapter_array_and_linkedlist/list.md | 28 ++--- .../backtracking_algorithm.md | 26 ++--- chapter_backtracking/n_queens_problem.md | 4 +- chapter_backtracking/permutations_problem.md | 8 +- chapter_backtracking/subset_sum_problem.md | 12 +- .../space_complexity.md | 36 +++--- .../time_complexity.md | 64 +++++------ chapter_data_structure/basic_data_types.md | 4 +- .../binary_search_recur.md | 4 +- .../build_binary_tree_problem.md | 4 +- chapter_divide_and_conquer/hanota_problem.md | 4 +- .../dp_problem_features.md | 12 +- .../dp_solution_pipeline.md | 16 +-- .../edit_distance_problem.md | 8 +- .../intro_to_dynamic_programming.md | 20 ++-- .../knapsack_problem.md | 16 +-- .../unbounded_knapsack_problem.md | 24 ++-- chapter_graph/graph_operations.md | 8 +- chapter_graph/graph_traversal.md | 8 +- chapter_greedy/fractional_knapsack_problem.md | 4 +- chapter_greedy/greedy_algorithm.md | 4 +- chapter_greedy/max_capacity_problem.md | 4 +- chapter_greedy/max_product_cutting_problem.md | 4 +- chapter_hashing/hash_algorithm.md | 8 +- chapter_hashing/hash_collision.md | 8 +- chapter_hashing/hash_map.md | 12 +- chapter_heap/build_heap.md | 4 +- chapter_heap/heap.md | 20 ++-- chapter_heap/top_k.md | 22 +++- chapter_preface/suggestions.md | 4 +- chapter_searching/binary_search.md | 8 +- chapter_searching/binary_search_edge.md | 8 +- .../replace_linear_by_hashing.md | 8 +- chapter_sorting/bubble_sort.md | 8 +- chapter_sorting/bucket_sort.md | 4 +- chapter_sorting/counting_sort.md | 8 +- chapter_sorting/heap_sort.md | 4 +- chapter_sorting/insertion_sort.md | 4 +- chapter_sorting/merge_sort.md | 4 +- chapter_sorting/quick_sort.md | 16 +-- chapter_sorting/radix_sort.md | 4 +- chapter_sorting/selection_sort.md | 4 +- chapter_stack_and_queue/deque.md | 12 +- chapter_stack_and_queue/queue.md | 12 +- chapter_stack_and_queue/stack.md | 12 +- chapter_tree/array_representation_of_tree.md | 104 +++++++++++++++++- chapter_tree/avl_tree.md | 42 +++---- chapter_tree/binary_search_tree.md | 24 ++-- chapter_tree/binary_tree.md | 12 +- chapter_tree/binary_tree_traversal.md | 12 +- 53 files changed, 439 insertions(+), 329 deletions(-) diff --git a/chapter_appendix/contribution.md b/chapter_appendix/contribution.md index 59dedf773..3ffe6da9b 100644 --- a/chapter_appendix/contribution.md +++ b/chapter_appendix/contribution.md @@ -36,7 +36,7 @@ comments: true ## 16.2.3.   Docker 部署 -我们可以通过 Docker 来部署本项目。执行以下脚本,稍等片刻后,即可使用浏览器打开 `http://localhost:8000` 来访问本项目。 +执行以下 Docker 脚本,稍等片刻,即可在网页 `http://localhost:8000` 访问本项目。 ```shell git clone https://github.com/krahets/hello-algo.git diff --git a/chapter_array_and_linkedlist/array.md b/chapter_array_and_linkedlist/array.md index 284c8e4d9..77f202cae 100755 --- a/chapter_array_and_linkedlist/array.md +++ b/chapter_array_and_linkedlist/array.md @@ -51,7 +51,7 @@ comments: true nums := []int{1, 3, 2, 5, 4} ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 初始化数组 */ @@ -59,7 +59,7 @@ comments: true var nums = [1, 3, 2, 5, 4]; ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 初始化数组 */ @@ -184,7 +184,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 随机返回一个数组元素 */ @@ -197,7 +197,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 随机返回一个数组元素 */ @@ -357,7 +357,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 扩展数组长度 */ @@ -375,7 +375,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 扩展数组长度 */ @@ -552,7 +552,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 在数组的索引 index 处插入元素 num */ @@ -566,7 +566,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 在数组的索引 index 处插入元素 num */ @@ -717,7 +717,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 删除索引 index 处元素 */ @@ -729,7 +729,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 删除索引 index 处元素 */ @@ -891,7 +891,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 遍历数组 */ @@ -908,7 +908,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 遍历数组 */ @@ -1084,7 +1084,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "JavaScript" +=== "JS" ```javascript title="array.js" /* 在数组中查找指定元素 */ @@ -1096,7 +1096,7 @@ elementAddr = firtstElementAddr + elementLength * elementIndex } ``` -=== "TypeScript" +=== "TS" ```typescript title="array.ts" /* 在数组中查找指定元素 */ diff --git a/chapter_array_and_linkedlist/linked_list.md b/chapter_array_and_linkedlist/linked_list.md index 489d8a1e6..9b0349dc0 100755 --- a/chapter_array_and_linkedlist/linked_list.md +++ b/chapter_array_and_linkedlist/linked_list.md @@ -64,7 +64,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 链表节点类 */ @@ -78,7 +78,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 链表节点类 */ @@ -253,7 +253,7 @@ comments: true n3.Next = n4 ``` -=== "JavaScript" +=== "JS" ```javascript title="linked_list.js" /* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */ @@ -270,7 +270,7 @@ comments: true n3.next = n4; ``` -=== "TypeScript" +=== "TS" ```typescript title="linked_list.ts" /* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */ @@ -429,7 +429,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linked_list.js" /* 在链表的节点 n0 之后插入节点 P */ @@ -440,7 +440,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linked_list.ts" /* 在链表的节点 n0 之后插入节点 P */ @@ -582,7 +582,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linked_list.js" /* 删除链表的节点 n0 之后的首个节点 */ @@ -595,7 +595,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linked_list.ts" /* 删除链表的节点 n0 之后的首个节点 */ @@ -758,7 +758,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linked_list.js" /* 访问链表中索引为 index 的节点 */ @@ -773,7 +773,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linked_list.ts" /* 访问链表中索引为 index 的节点 */ @@ -941,7 +941,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linked_list.js" /* 在链表中查找值为 target 的首个节点 */ @@ -958,7 +958,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linked_list.ts" /* 在链表中查找值为 target 的首个节点 */ @@ -1134,7 +1134,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 双向链表节点类 */ @@ -1150,7 +1150,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 双向链表节点类 */ diff --git a/chapter_array_and_linkedlist/list.md b/chapter_array_and_linkedlist/list.md index 8fc96f91a..e995fb16f 100755 --- a/chapter_array_and_linkedlist/list.md +++ b/chapter_array_and_linkedlist/list.md @@ -54,7 +54,7 @@ comments: true list := []int{1, 3, 2, 5, 4} ``` -=== "JavaScript" +=== "JS" ```javascript title="list.js" /* 初始化列表 */ @@ -64,7 +64,7 @@ comments: true const list = [1, 3, 2, 5, 4]; ``` -=== "TypeScript" +=== "TS" ```typescript title="list.ts" /* 初始化列表 */ @@ -168,7 +168,7 @@ comments: true list[1] = 0 // 将索引 1 处的元素更新为 0 ``` -=== "JavaScript" +=== "JS" ```javascript title="list.js" /* 访问元素 */ @@ -178,7 +178,7 @@ comments: true list[1] = 0; // 将索引 1 处的元素更新为 0 ``` -=== "TypeScript" +=== "TS" ```typescript title="list.ts" /* 访问元素 */ @@ -322,7 +322,7 @@ comments: true list = append(list[:3], list[4:]...) // 删除索引 3 处的元素 ``` -=== "JavaScript" +=== "JS" ```javascript title="list.js" /* 清空列表 */ @@ -342,7 +342,7 @@ comments: true list.splice(3, 1); ``` -=== "TypeScript" +=== "TS" ```typescript title="list.ts" /* 清空列表 */ @@ -518,7 +518,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="list.js" /* 通过索引遍历列表 */ @@ -534,7 +534,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="list.ts" /* 通过索引遍历列表 */ @@ -662,7 +662,7 @@ comments: true list = append(list, list1...) // 将列表 list1 拼接到 list 之后 ``` -=== "JavaScript" +=== "JS" ```javascript title="list.js" /* 拼接两个列表 */ @@ -670,7 +670,7 @@ comments: true list.push(...list1); // 将列表 list1 拼接到 list 之后 ``` -=== "TypeScript" +=== "TS" ```typescript title="list.ts" /* 拼接两个列表 */ @@ -754,14 +754,14 @@ comments: true sort.Ints(list) // 排序后,列表元素从小到大排列 ``` -=== "JavaScript" +=== "JS" ```javascript title="list.js" /* 排序列表 */ list.sort((a, b) => a - b); // 排序后,列表元素从小到大排列 ``` -=== "TypeScript" +=== "TS" ```typescript title="list.ts" /* 排序列表 */ @@ -1224,7 +1224,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="my_list.js" /* 列表类简易实现 */ @@ -1326,7 +1326,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="my_list.ts" /* 列表类简易实现 */ diff --git a/chapter_backtracking/backtracking_algorithm.md b/chapter_backtracking/backtracking_algorithm.md index 68c22ed3b..71d2af330 100644 --- a/chapter_backtracking/backtracking_algorithm.md +++ b/chapter_backtracking/backtracking_algorithm.md @@ -70,7 +70,7 @@ comments: true if root == nil { return } - if int(root.Val) == 7 { + if (root.Val).(int) == 7 { // 记录解 *res = append(*res, root) } @@ -79,7 +79,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="preorder_traversal_i_compact.js" /* 前序遍历:例题一 */ @@ -96,7 +96,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="preorder_traversal_i_compact.ts" /* 前序遍历:例题一 */ @@ -272,7 +272,7 @@ comments: true } // 尝试 *path = append(*path, root) - if int(root.Val) == 7 { + if root.Val.(int) == 7 { // 记录解 *res = append(*res, *path) } @@ -283,7 +283,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="preorder_traversal_ii_compact.js" /* 前序遍历:例题二 */ @@ -304,7 +304,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="preorder_traversal_ii_compact.ts" /* 前序遍历:例题二 */ @@ -539,7 +539,7 @@ comments: true } // 尝试 *path = append(*path, root) - if int(root.Val) == 7 { + if root.Val.(int) == 7 { // 记录解 *res = append(*res, *path) *path = (*path)[:len(*path)-1] @@ -552,7 +552,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="preorder_traversal_iii_compact.js" /* 前序遍历:例题三 */ @@ -576,7 +576,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="preorder_traversal_iii_compact.ts" /* 前序遍历:例题三 */ @@ -808,7 +808,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 回溯算法框架 */ @@ -834,7 +834,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 回溯算法框架 */ @@ -1174,7 +1174,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="preorder_traversal_iii_template.js" /* 判断当前状态是否为解 */ @@ -1224,7 +1224,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="preorder_traversal_iii_template.ts" /* 判断当前状态是否为解 */ diff --git a/chapter_backtracking/n_queens_problem.md b/chapter_backtracking/n_queens_problem.md index 8cdcb70bb..e858c16d0 100644 --- a/chapter_backtracking/n_queens_problem.md +++ b/chapter_backtracking/n_queens_problem.md @@ -284,7 +284,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="n_queens.js" /* 回溯算法:N 皇后 */ @@ -327,7 +327,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="n_queens.ts" /* 回溯算法:N 皇后 */ diff --git a/chapter_backtracking/permutations_problem.md b/chapter_backtracking/permutations_problem.md index 80c5f382c..6dc9f026a 100644 --- a/chapter_backtracking/permutations_problem.md +++ b/chapter_backtracking/permutations_problem.md @@ -193,7 +193,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="permutations_i.js" /* 回溯算法:全排列 I */ @@ -227,7 +227,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="permutations_i.ts" /* 回溯算法:全排列 I */ @@ -577,7 +577,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="permutations_ii.js" /* 回溯算法:全排列 II */ @@ -613,7 +613,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="permutations_ii.ts" /* 回溯算法:全排列 II */ diff --git a/chapter_backtracking/subset_sum_problem.md b/chapter_backtracking/subset_sum_problem.md index 42bf90b41..b54b7cf0c 100644 --- a/chapter_backtracking/subset_sum_problem.md +++ b/chapter_backtracking/subset_sum_problem.md @@ -163,7 +163,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="subset_sum_i_naive.js" [class]{}-[func]{backtrack} @@ -171,7 +171,7 @@ comments: true [class]{}-[func]{subsetSumINaive} ``` -=== "TypeScript" +=== "TS" ```typescript title="subset_sum_i_naive.ts" [class]{}-[func]{backtrack} @@ -499,7 +499,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="subset_sum_i.js" [class]{}-[func]{backtrack} @@ -507,7 +507,7 @@ comments: true [class]{}-[func]{subsetSumI} ``` -=== "TypeScript" +=== "TS" ```typescript title="subset_sum_i.ts" [class]{}-[func]{backtrack} @@ -850,7 +850,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="subset_sum_ii.js" [class]{}-[func]{backtrack} @@ -858,7 +858,7 @@ comments: true [class]{}-[func]{subsetSumII} ``` -=== "TypeScript" +=== "TS" ```typescript title="subset_sum_ii.ts" [class]{}-[func]{backtrack} diff --git a/chapter_computational_complexity/space_complexity.md b/chapter_computational_complexity/space_complexity.md index 5a1378240..2741952ae 100755 --- a/chapter_computational_complexity/space_complexity.md +++ b/chapter_computational_complexity/space_complexity.md @@ -129,7 +129,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 类 */ @@ -157,7 +157,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 类 */ @@ -347,7 +347,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" function algorithm(n) { @@ -359,7 +359,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" function algorithm(n: number): void { @@ -514,7 +514,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" function constFunc() { @@ -534,7 +534,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" function constFunc(): number { @@ -758,7 +758,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="space_complexity.js" /* 常数阶 */ @@ -779,7 +779,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="space_complexity.ts" /* 常数阶 */ @@ -1012,7 +1012,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="space_complexity.js" /* 线性阶 */ @@ -1032,7 +1032,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="space_complexity.ts" /* 线性阶 */ @@ -1251,7 +1251,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="space_complexity.js" /* 线性阶(递归实现) */ @@ -1262,7 +1262,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="space_complexity.ts" /* 线性阶(递归实现) */ @@ -1408,7 +1408,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="space_complexity.js" /* 平方阶 */ @@ -1429,7 +1429,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="space_complexity.ts" /* 平方阶 */ @@ -1618,7 +1618,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="space_complexity.js" /* 平方阶(递归实现) */ @@ -1630,7 +1630,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="space_complexity.ts" /* 平方阶(递归实现) */ @@ -1786,7 +1786,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="space_complexity.js" /* 指数阶(建立满二叉树) */ @@ -1799,7 +1799,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="space_complexity.ts" /* 指数阶(建立满二叉树) */ diff --git a/chapter_computational_complexity/time_complexity.md b/chapter_computational_complexity/time_complexity.md index 11d404a61..d95ce3d5e 100755 --- a/chapter_computational_complexity/time_complexity.md +++ b/chapter_computational_complexity/time_complexity.md @@ -76,7 +76,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="" // 在某运行平台下 @@ -91,7 +91,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="" // 在某运行平台下 @@ -269,7 +269,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="" // 算法 A 时间复杂度:常数阶 @@ -291,7 +291,7 @@ $$ ``` -=== "TypeScript" +=== "TS" ```typescript title="" // 算法 A 时间复杂度:常数阶 @@ -484,7 +484,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="" function algorithm(n) { @@ -498,7 +498,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="" function algorithm(n: number): void{ @@ -701,7 +701,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="" function algorithm(n) { @@ -720,7 +720,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="" function algorithm(n: number): void { @@ -922,7 +922,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 常数阶 */ @@ -934,7 +934,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 常数阶 */ @@ -1085,7 +1085,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 线性阶 */ @@ -1096,7 +1096,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 线性阶 */ @@ -1245,7 +1245,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 线性阶(遍历数组) */ @@ -1259,7 +1259,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 线性阶(遍历数组) */ @@ -1422,7 +1422,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 平方阶 */ @@ -1438,7 +1438,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 平方阶 */ @@ -1650,7 +1650,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 平方阶(冒泡排序) */ @@ -1673,7 +1673,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 平方阶(冒泡排序) */ @@ -1912,7 +1912,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 指数阶(循环实现) */ @@ -1931,7 +1931,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 指数阶(循环实现) */ @@ -2114,7 +2114,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 指数阶(递归实现) */ @@ -2124,7 +2124,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 指数阶(递归实现) */ @@ -2261,7 +2261,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 对数阶(循环实现) */ @@ -2275,7 +2275,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 对数阶(循环实现) */ @@ -2426,7 +2426,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 对数阶(递归实现) */ @@ -2436,7 +2436,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 对数阶(递归实现) */ @@ -2578,7 +2578,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 线性对数阶 */ @@ -2592,7 +2592,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 线性对数阶 */ @@ -2776,7 +2776,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="time_complexity.js" /* 阶乘阶(递归实现) */ @@ -2791,7 +2791,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="time_complexity.ts" /* 阶乘阶(递归实现) */ @@ -3026,7 +3026,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="worst_best_time_complexity.js" /* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ @@ -3059,7 +3059,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="worst_best_time_complexity.ts" /* 生成一个数组,元素为 { 1, 2, ..., n },顺序被打乱 */ diff --git a/chapter_data_structure/basic_data_types.md b/chapter_data_structure/basic_data_types.md index a2b2b506e..a0135b71e 100644 --- a/chapter_data_structure/basic_data_types.md +++ b/chapter_data_structure/basic_data_types.md @@ -82,14 +82,14 @@ comments: true var booleans = [5]bool{} ``` -=== "JavaScript" +=== "JS" ```javascript title="" // JavaScript 的数组可以自由存储各种基本数据类型和对象 const array = [0, 0.0, 'a', false]; ``` -=== "TypeScript" +=== "TS" ```typescript title="" // 使用多种基本数据类型来初始化数组 diff --git a/chapter_divide_and_conquer/binary_search_recur.md b/chapter_divide_and_conquer/binary_search_recur.md index e2ca3ecf4..1d2d1cf58 100644 --- a/chapter_divide_and_conquer/binary_search_recur.md +++ b/chapter_divide_and_conquer/binary_search_recur.md @@ -169,7 +169,7 @@ status: new } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search_recur.js" [class]{}-[func]{dfs} @@ -177,7 +177,7 @@ status: new [class]{}-[func]{binarySearch} ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search_recur.ts" [class]{}-[func]{dfs} diff --git a/chapter_divide_and_conquer/build_binary_tree_problem.md b/chapter_divide_and_conquer/build_binary_tree_problem.md index ae5fc814f..8add6d0f5 100644 --- a/chapter_divide_and_conquer/build_binary_tree_problem.md +++ b/chapter_divide_and_conquer/build_binary_tree_problem.md @@ -202,7 +202,7 @@ status: new } ``` -=== "JavaScript" +=== "JS" ```javascript title="build_tree.js" [class]{}-[func]{dfs} @@ -210,7 +210,7 @@ status: new [class]{}-[func]{buildTree} ``` -=== "TypeScript" +=== "TS" ```typescript title="build_tree.ts" [class]{}-[func]{dfs} diff --git a/chapter_divide_and_conquer/hanota_problem.md b/chapter_divide_and_conquer/hanota_problem.md index 0750580a5..ce9ece326 100644 --- a/chapter_divide_and_conquer/hanota_problem.md +++ b/chapter_divide_and_conquer/hanota_problem.md @@ -226,7 +226,7 @@ status: new } ``` -=== "JavaScript" +=== "JS" ```javascript title="hanota.js" [class]{}-[func]{move} @@ -236,7 +236,7 @@ status: new [class]{}-[func]{hanota} ``` -=== "TypeScript" +=== "TS" ```typescript title="hanota.ts" [class]{}-[func]{move} diff --git a/chapter_dynamic_programming/dp_problem_features.md b/chapter_dynamic_programming/dp_problem_features.md index 391a236c8..70d6b09cf 100644 --- a/chapter_dynamic_programming/dp_problem_features.md +++ b/chapter_dynamic_programming/dp_problem_features.md @@ -123,13 +123,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="min_cost_climbing_stairs_dp.js" [class]{}-[func]{minCostClimbingStairsDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="min_cost_climbing_stairs_dp.ts" [class]{}-[func]{minCostClimbingStairsDP} @@ -309,13 +309,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="min_cost_climbing_stairs_dp.js" [class]{}-[func]{minCostClimbingStairsDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="min_cost_climbing_stairs_dp.ts" [class]{}-[func]{minCostClimbingStairsDPComp} @@ -539,13 +539,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="climbing_stairs_constraint_dp.js" [class]{}-[func]{climbingStairsConstraintDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="climbing_stairs_constraint_dp.ts" [class]{}-[func]{climbingStairsConstraintDP} diff --git a/chapter_dynamic_programming/dp_solution_pipeline.md b/chapter_dynamic_programming/dp_solution_pipeline.md index d2afa9ec1..0494e3fa2 100644 --- a/chapter_dynamic_programming/dp_solution_pipeline.md +++ b/chapter_dynamic_programming/dp_solution_pipeline.md @@ -192,13 +192,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="min_path_sum.js" [class]{}-[func]{minPathSumDFS} ``` -=== "TypeScript" +=== "TS" ```typescript title="min_path_sum.ts" [class]{}-[func]{minPathSumDFS} @@ -416,13 +416,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="min_path_sum.js" [class]{}-[func]{minPathSumDFSMem} ``` -=== "TypeScript" +=== "TS" ```typescript title="min_path_sum.ts" [class]{}-[func]{minPathSumDFSMem} @@ -661,13 +661,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="min_path_sum.js" [class]{}-[func]{minPathSumDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="min_path_sum.ts" [class]{}-[func]{minPathSumDP} @@ -941,13 +941,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="min_path_sum.js" [class]{}-[func]{minPathSumDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="min_path_sum.ts" [class]{}-[func]{minPathSumDPComp} diff --git a/chapter_dynamic_programming/edit_distance_problem.md b/chapter_dynamic_programming/edit_distance_problem.md index 9b46b399a..5984bde99 100644 --- a/chapter_dynamic_programming/edit_distance_problem.md +++ b/chapter_dynamic_programming/edit_distance_problem.md @@ -194,13 +194,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="edit_distance.js" [class]{}-[func]{editDistanceDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="edit_distance.ts" [class]{}-[func]{editDistanceDP} @@ -521,13 +521,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="edit_distance.js" [class]{}-[func]{editDistanceDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="edit_distance.ts" [class]{}-[func]{editDistanceDPComp} diff --git a/chapter_dynamic_programming/intro_to_dynamic_programming.md b/chapter_dynamic_programming/intro_to_dynamic_programming.md index be3092ca5..e964efea9 100644 --- a/chapter_dynamic_programming/intro_to_dynamic_programming.md +++ b/chapter_dynamic_programming/intro_to_dynamic_programming.md @@ -141,7 +141,7 @@ status: new } ``` -=== "JavaScript" +=== "JS" ```javascript title="climbing_stairs_backtrack.js" [class]{}-[func]{backtrack} @@ -149,7 +149,7 @@ status: new [class]{}-[func]{climbingStairsBacktrack} ``` -=== "TypeScript" +=== "TS" ```typescript title="climbing_stairs_backtrack.ts" [class]{}-[func]{backtrack} @@ -399,7 +399,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="climbing_stairs_dfs.js" [class]{}-[func]{dfs} @@ -407,7 +407,7 @@ $$ [class]{}-[func]{climbingStairsDFS} ``` -=== "TypeScript" +=== "TS" ```typescript title="climbing_stairs_dfs.ts" [class]{}-[func]{dfs} @@ -633,7 +633,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="climbing_stairs_dfs_mem.js" [class]{}-[func]{dfs} @@ -641,7 +641,7 @@ $$ [class]{}-[func]{climbingStairsDFSMem} ``` -=== "TypeScript" +=== "TS" ```typescript title="climbing_stairs_dfs_mem.ts" [class]{}-[func]{dfs} @@ -864,13 +864,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="climbing_stairs_dp.js" [class]{}-[func]{climbingStairsDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="climbing_stairs_dp.ts" [class]{}-[func]{climbingStairsDP} @@ -1051,13 +1051,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="climbing_stairs_dp.js" [class]{}-[func]{climbingStairsDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="climbing_stairs_dp.ts" [class]{}-[func]{climbingStairsDPComp} diff --git a/chapter_dynamic_programming/knapsack_problem.md b/chapter_dynamic_programming/knapsack_problem.md index 778ea1617..02fddb72e 100644 --- a/chapter_dynamic_programming/knapsack_problem.md +++ b/chapter_dynamic_programming/knapsack_problem.md @@ -144,13 +144,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="knapsack.js" [class]{}-[func]{knapsackDFS} ``` -=== "TypeScript" +=== "TS" ```typescript title="knapsack.ts" [class]{}-[func]{knapsackDFS} @@ -368,13 +368,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="knapsack.js" [class]{}-[func]{knapsackDFSMem} ``` -=== "TypeScript" +=== "TS" ```typescript title="knapsack.ts" [class]{}-[func]{knapsackDFSMem} @@ -599,13 +599,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="knapsack.js" [class]{}-[func]{knapsackDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="knapsack.ts" [class]{}-[func]{knapsackDP} @@ -881,13 +881,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="knapsack.js" [class]{}-[func]{knapsackDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="knapsack.ts" [class]{}-[func]{knapsackDPComp} diff --git a/chapter_dynamic_programming/unbounded_knapsack_problem.md b/chapter_dynamic_programming/unbounded_knapsack_problem.md index cb8bec09f..dfd324428 100644 --- a/chapter_dynamic_programming/unbounded_knapsack_problem.md +++ b/chapter_dynamic_programming/unbounded_knapsack_problem.md @@ -132,13 +132,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="unbounded_knapsack.js" [class]{}-[func]{unboundedKnapsackDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="unbounded_knapsack.ts" [class]{}-[func]{unboundedKnapsackDP} @@ -371,13 +371,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="unbounded_knapsack.js" [class]{}-[func]{unboundedKnapsackDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="unbounded_knapsack.ts" [class]{}-[func]{unboundedKnapsackDPComp} @@ -657,13 +657,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="coin_change.js" [class]{}-[func]{coinChangeDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="coin_change.ts" [class]{}-[func]{coinChangeDP} @@ -960,13 +960,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="coin_change.js" [class]{}-[func]{coinChangeDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="coin_change.ts" [class]{}-[func]{coinChangeDPComp} @@ -1227,13 +1227,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="coin_change_ii.js" [class]{}-[func]{coinChangeIIDP} ``` -=== "TypeScript" +=== "TS" ```typescript title="coin_change_ii.ts" [class]{}-[func]{coinChangeIIDP} @@ -1465,13 +1465,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="coin_change_ii.js" [class]{}-[func]{coinChangeIIDPComp} ``` -=== "TypeScript" +=== "TS" ```typescript title="coin_change_ii.ts" [class]{}-[func]{coinChangeIIDPComp} diff --git a/chapter_graph/graph_operations.md b/chapter_graph/graph_operations.md index 4651de22e..002b3586e 100644 --- a/chapter_graph/graph_operations.md +++ b/chapter_graph/graph_operations.md @@ -386,7 +386,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="graph_adjacency_matrix.js" /* 基于邻接矩阵实现的无向图类 */ @@ -478,7 +478,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="graph_adjacency_matrix.ts" /* 基于邻接矩阵实现的无向图类 */ @@ -1466,7 +1466,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="graph_adjacency_list.js" /* 基于邻接表实现的无向图类 */ @@ -1555,7 +1555,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="graph_adjacency_list.ts" /* 基于邻接表实现的无向图类 */ diff --git a/chapter_graph/graph_traversal.md b/chapter_graph/graph_traversal.md index 82abb8986..62f9c8a1a 100644 --- a/chapter_graph/graph_traversal.md +++ b/chapter_graph/graph_traversal.md @@ -154,7 +154,7 @@ BFS 通常借助「队列」来实现。队列具有“先入先出”的性质 } ``` -=== "JavaScript" +=== "JS" ```javascript title="graph_bfs.js" /* 广度优先遍历 BFS */ @@ -185,7 +185,7 @@ BFS 通常借助「队列」来实现。队列具有“先入先出”的性质 } ``` -=== "TypeScript" +=== "TS" ```typescript title="graph_bfs.ts" /* 广度优先遍历 BFS */ @@ -561,7 +561,7 @@ BFS 通常借助「队列」来实现。队列具有“先入先出”的性质 } ``` -=== "JavaScript" +=== "JS" ```javascript title="graph_dfs.js" /* 深度优先遍历 DFS */ @@ -591,7 +591,7 @@ BFS 通常借助「队列」来实现。队列具有“先入先出”的性质 } ``` -=== "TypeScript" +=== "TS" ```typescript title="graph_dfs.ts" /* 深度优先遍历 DFS 辅助函数 */ diff --git a/chapter_greedy/fractional_knapsack_problem.md b/chapter_greedy/fractional_knapsack_problem.md index b50fedbf2..153bc3c1a 100644 --- a/chapter_greedy/fractional_knapsack_problem.md +++ b/chapter_greedy/fractional_knapsack_problem.md @@ -192,7 +192,7 @@ status: new } ``` -=== "JavaScript" +=== "JS" ```javascript title="fractional_knapsack.js" [class]{Item}-[func]{} @@ -200,7 +200,7 @@ status: new [class]{}-[func]{fractionalKnapsack} ``` -=== "TypeScript" +=== "TS" ```typescript title="fractional_knapsack.ts" [class]{Item}-[func]{} diff --git a/chapter_greedy/greedy_algorithm.md b/chapter_greedy/greedy_algorithm.md index 6f9e22459..bcc83cbd2 100644 --- a/chapter_greedy/greedy_algorithm.md +++ b/chapter_greedy/greedy_algorithm.md @@ -118,13 +118,13 @@ status: new } ``` -=== "JavaScript" +=== "JS" ```javascript title="coin_change_greedy.js" [class]{}-[func]{coinChangeGreedy} ``` -=== "TypeScript" +=== "TS" ```typescript title="coin_change_greedy.ts" [class]{}-[func]{coinChangeGreedy} diff --git a/chapter_greedy/max_capacity_problem.md b/chapter_greedy/max_capacity_problem.md index 78513635a..03c6e5b07 100644 --- a/chapter_greedy/max_capacity_problem.md +++ b/chapter_greedy/max_capacity_problem.md @@ -187,13 +187,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="max_capacity.js" [class]{}-[func]{maxCapacity} ``` -=== "TypeScript" +=== "TS" ```typescript title="max_capacity.ts" [class]{}-[func]{maxCapacity} diff --git a/chapter_greedy/max_product_cutting_problem.md b/chapter_greedy/max_product_cutting_problem.md index 3539f94df..183df2903 100644 --- a/chapter_greedy/max_product_cutting_problem.md +++ b/chapter_greedy/max_product_cutting_problem.md @@ -169,13 +169,13 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="max_product_cutting.js" [class]{}-[func]{maxProductCutting} ``` -=== "TypeScript" +=== "TS" ```typescript title="max_product_cutting.ts" [class]{}-[func]{maxProductCutting} diff --git a/chapter_hashing/hash_algorithm.md b/chapter_hashing/hash_algorithm.md index 2b6e57f16..284e71be2 100644 --- a/chapter_hashing/hash_algorithm.md +++ b/chapter_hashing/hash_algorithm.md @@ -228,7 +228,7 @@ index = hash(key) % capacity } ``` -=== "JavaScript" +=== "JS" ```javascript title="simple_hash.js" [class]{}-[func]{addHash} @@ -240,7 +240,7 @@ index = hash(key) % capacity [class]{}-[func]{rotHash} ``` -=== "TypeScript" +=== "TS" ```typescript title="simple_hash.ts" [class]{}-[func]{addHash} @@ -542,13 +542,13 @@ $$ ``` -=== "JavaScript" +=== "JS" ```javascript title="built_in_hash.js" ``` -=== "TypeScript" +=== "TS" ```typescript title="built_in_hash.ts" diff --git a/chapter_hashing/hash_collision.md b/chapter_hashing/hash_collision.md index 63d40c37d..9a062a3e9 100644 --- a/chapter_hashing/hash_collision.md +++ b/chapter_hashing/hash_collision.md @@ -465,13 +465,13 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="hash_map_chaining.js" [class]{HashMapChaining}-[func]{} ``` -=== "TypeScript" +=== "TS" ```typescript title="hash_map_chaining.ts" [class]{HashMapChaining}-[func]{} @@ -1321,13 +1321,13 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="hash_map_open_addressing.js" [class]{HashMapOpenAddressing}-[func]{} ``` -=== "TypeScript" +=== "TS" ```typescript title="hash_map_open_addressing.ts" [class]{HashMapOpenAddressing}-[func]{} diff --git a/chapter_hashing/hash_map.md b/chapter_hashing/hash_map.md index 4553b3eb1..345e30d37 100755 --- a/chapter_hashing/hash_map.md +++ b/chapter_hashing/hash_map.md @@ -126,7 +126,7 @@ comments: true delete(mapp, 10583) ``` -=== "JavaScript" +=== "JS" ```javascript title="hash_map.js" /* 初始化哈希表 */ @@ -148,7 +148,7 @@ comments: true map.delete(10583); ``` -=== "TypeScript" +=== "TS" ```typescript title="hash_map.ts" /* 初始化哈希表 */ @@ -333,7 +333,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="hash_map.js" /* 遍历哈希表 */ @@ -351,7 +351,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="hash_map.ts" /* 遍历哈希表 */ @@ -835,7 +835,7 @@ index = hash(key) % capacity } ``` -=== "JavaScript" +=== "JS" ```javascript title="array_hash_map.js" /* 键值对 Number -> String */ @@ -924,7 +924,7 @@ index = hash(key) % capacity } ``` -=== "TypeScript" +=== "TS" ```typescript title="array_hash_map.ts" /* 键值对 Number -> String */ diff --git a/chapter_heap/build_heap.md b/chapter_heap/build_heap.md index 48eec419f..d78f75b4b 100644 --- a/chapter_heap/build_heap.md +++ b/chapter_heap/build_heap.md @@ -71,7 +71,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="my_heap.js" /* 构造方法,建立空堆或根据输入列表建堆 */ @@ -85,7 +85,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="my_heap.ts" /* 构造方法,建立空堆或根据输入列表建堆 */ diff --git a/chapter_heap/heap.md b/chapter_heap/heap.md index 7c10098f4..08197cee0 100644 --- a/chapter_heap/heap.md +++ b/chapter_heap/heap.md @@ -240,13 +240,13 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="heap.js" // JavaScript 未提供内置 Heap 类 ``` -=== "TypeScript" +=== "TS" ```typescript title="heap.ts" // TypeScript 未提供内置 Heap 类 @@ -411,7 +411,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="my_heap.js" /* 获取左子节点索引 */ @@ -430,7 +430,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="my_heap.ts" /* 获取左子节点索引 */ @@ -603,7 +603,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="my_heap.js" /* 访问堆顶元素 */ @@ -612,7 +612,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="my_heap.ts" /* 访问堆顶元素 */ @@ -816,7 +816,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="my_heap.js" /* 元素入堆 */ @@ -842,7 +842,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="my_heap.ts" /* 元素入堆 */ @@ -1229,7 +1229,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="my_heap.js" /* 元素出堆 */ @@ -1265,7 +1265,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="my_heap.ts" /* 元素出堆 */ diff --git a/chapter_heap/top_k.md b/chapter_heap/top_k.md index a0d8bfdf2..8f73eca63 100644 --- a/chapter_heap/top_k.md +++ b/chapter_heap/top_k.md @@ -159,13 +159,13 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="top_k.js" [class]{}-[func]{topKHeap} ``` -=== "TypeScript" +=== "TS" ```typescript title="top_k.ts" [class]{}-[func]{topKHeap} @@ -180,7 +180,23 @@ comments: true === "C#" ```csharp title="top_k.cs" - [class]{top_k}-[func]{topKHeap} + /* 基于堆查找数组中最大的 k 个元素 */ + PriorityQueue topKHeap(int[] nums, int k) { + PriorityQueue heap = new PriorityQueue(); + // 将数组的前 k 个元素入堆 + for (int i = 0; i < k; i++) { + heap.Enqueue(nums[i], nums[i]); + } + // 从第 k+1 个元素开始,保持堆的长度为 k + for (int i = k; i < nums.Length; i++) { + // 若当前元素大于堆顶元素,则将堆顶元素出堆、当前元素入堆 + if (nums[i] > heap.Peek()) { + heap.Dequeue(); + heap.Enqueue(nums[i], nums[i]); + } + } + return heap; + } ``` === "Swift" diff --git a/chapter_preface/suggestions.md b/chapter_preface/suggestions.md index 3924d7896..75f99153d 100644 --- a/chapter_preface/suggestions.md +++ b/chapter_preface/suggestions.md @@ -69,7 +69,7 @@ comments: true */ ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 标题注释,用于标注函数、类、测试样例等 */ @@ -82,7 +82,7 @@ comments: true */ ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 标题注释,用于标注函数、类、测试样例等 */ diff --git a/chapter_searching/binary_search.md b/chapter_searching/binary_search.md index 7543d5f7f..636285e97 100755 --- a/chapter_searching/binary_search.md +++ b/chapter_searching/binary_search.md @@ -135,7 +135,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search.js" /* 二分查找(双闭区间) */ @@ -160,7 +160,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search.ts" /* 二分查找(双闭区间) */ @@ -425,7 +425,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search.js" /* 二分查找(左闭右开) */ @@ -451,7 +451,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search.ts" /* 二分查找(左闭右开) */ diff --git a/chapter_searching/binary_search_edge.md b/chapter_searching/binary_search_edge.md index 7c8c12fea..85edbbdd1 100644 --- a/chapter_searching/binary_search_edge.md +++ b/chapter_searching/binary_search_edge.md @@ -148,7 +148,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search_edge.js" /* 二分查找最左一个元素 */ @@ -172,7 +172,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search_edge.ts" /* 二分查找最左一个元素 */ @@ -408,7 +408,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search_edge.js" /* 二分查找最右一个元素 */ @@ -432,7 +432,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search_edge.ts" /* 二分查找最右一个元素 */ diff --git a/chapter_searching/replace_linear_by_hashing.md b/chapter_searching/replace_linear_by_hashing.md index c8cf1148a..1fc706a96 100755 --- a/chapter_searching/replace_linear_by_hashing.md +++ b/chapter_searching/replace_linear_by_hashing.md @@ -83,7 +83,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="two_sum.js" /* 方法一:暴力枚举 */ @@ -101,7 +101,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="two_sum.ts" /* 方法一:暴力枚举 */ @@ -317,7 +317,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="two_sum.js" /* 方法二:辅助哈希表 */ @@ -336,7 +336,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="two_sum.ts" /* 方法二:辅助哈希表 */ diff --git a/chapter_sorting/bubble_sort.md b/chapter_sorting/bubble_sort.md index 6af05fcca..b67a47d13 100755 --- a/chapter_sorting/bubble_sort.md +++ b/chapter_sorting/bubble_sort.md @@ -114,7 +114,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="bubble_sort.js" /* 冒泡排序 */ @@ -134,7 +134,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="bubble_sort.ts" /* 冒泡排序 */ @@ -370,7 +370,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="bubble_sort.js" /* 冒泡排序(标志优化)*/ @@ -393,7 +393,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="bubble_sort.ts" /* 冒泡排序(标志优化)*/ diff --git a/chapter_sorting/bucket_sort.md b/chapter_sorting/bucket_sort.md index 7f0386c37..4d440bf3b 100644 --- a/chapter_sorting/bucket_sort.md +++ b/chapter_sorting/bucket_sort.md @@ -143,7 +143,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="bucket_sort.js" /* 桶排序 */ @@ -176,7 +176,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="bucket_sort.ts" /* 桶排序 */ diff --git a/chapter_sorting/counting_sort.md b/chapter_sorting/counting_sort.md index d0bff8009..bcb24ecd9 100644 --- a/chapter_sorting/counting_sort.md +++ b/chapter_sorting/counting_sort.md @@ -124,7 +124,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="counting_sort.js" /* 计数排序 */ @@ -151,7 +151,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="counting_sort.ts" /* 计数排序 */ @@ -508,7 +508,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="counting_sort.js" /* 计数排序 */ @@ -546,7 +546,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="counting_sort.ts" /* 计数排序 */ diff --git a/chapter_sorting/heap_sort.md b/chapter_sorting/heap_sort.md index 1b120b6d3..b098a6dd9 100644 --- a/chapter_sorting/heap_sort.md +++ b/chapter_sorting/heap_sort.md @@ -227,7 +227,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="heap_sort.js" /* 堆的长度为 n ,从节点 i 开始,从顶至底堆化 */ @@ -270,7 +270,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="heap_sort.ts" /* 堆的长度为 n ,从节点 i 开始,从顶至底堆化 */ diff --git a/chapter_sorting/insertion_sort.md b/chapter_sorting/insertion_sort.md index 15dfaee2b..6c8aaf4b8 100755 --- a/chapter_sorting/insertion_sort.md +++ b/chapter_sorting/insertion_sort.md @@ -98,7 +98,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="insertion_sort.js" /* 插入排序 */ @@ -117,7 +117,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="insertion_sort.ts" /* 插入排序 */ diff --git a/chapter_sorting/merge_sort.md b/chapter_sorting/merge_sort.md index 744e4eaa4..c2011d7ae 100755 --- a/chapter_sorting/merge_sort.md +++ b/chapter_sorting/merge_sort.md @@ -240,7 +240,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="merge_sort.js" /* 合并左子数组和右子数组 */ @@ -286,7 +286,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="merge_sort.ts" /* 合并左子数组和右子数组 */ diff --git a/chapter_sorting/quick_sort.md b/chapter_sorting/quick_sort.md index eb0aabb25..1cecabed9 100755 --- a/chapter_sorting/quick_sort.md +++ b/chapter_sorting/quick_sort.md @@ -139,7 +139,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="quick_sort.js" /* 元素交换 */ @@ -169,7 +169,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="quick_sort.ts" /* 元素交换 */ @@ -432,7 +432,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="quick_sort.js" /* 快速排序 */ @@ -447,7 +447,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="quick_sort.ts" /* 快速排序 */ @@ -750,7 +750,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="quick_sort.js" /* 选取三个元素的中位数 */ @@ -787,7 +787,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="quick_sort.ts" /* 选取三个元素的中位数 */ @@ -1138,7 +1138,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="quick_sort.js" /* 快速排序(尾递归优化) */ @@ -1159,7 +1159,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="quick_sort.ts" /* 快速排序(尾递归优化) */ diff --git a/chapter_sorting/radix_sort.md b/chapter_sorting/radix_sort.md index cf6d84177..b28e610b7 100644 --- a/chapter_sorting/radix_sort.md +++ b/chapter_sorting/radix_sort.md @@ -236,7 +236,7 @@ $$ } ``` -=== "JavaScript" +=== "JS" ```javascript title="radix_sort.js" /* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */ @@ -293,7 +293,7 @@ $$ } ``` -=== "TypeScript" +=== "TS" ```typescript title="radix_sort.ts" /* 获取元素 num 的第 k 位,其中 exp = 10^(k-1) */ diff --git a/chapter_sorting/selection_sort.md b/chapter_sorting/selection_sort.md index 5a1063158..9cd9da7d1 100644 --- a/chapter_sorting/selection_sort.md +++ b/chapter_sorting/selection_sort.md @@ -131,7 +131,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="selection_sort.js" /* 选择排序 */ @@ -152,7 +152,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="selection_sort.ts" /* 选择排序 */ diff --git a/chapter_stack_and_queue/deque.md b/chapter_stack_and_queue/deque.md index 28c1698f4..9d725cd2b 100644 --- a/chapter_stack_and_queue/deque.md +++ b/chapter_stack_and_queue/deque.md @@ -142,7 +142,7 @@ comments: true isEmpty := deque.Len() == 0 ``` -=== "JavaScript" +=== "JS" ```javascript title="deque.js" /* 初始化双向队列 */ @@ -180,7 +180,7 @@ comments: true console.log("双向队列是否为空 = " + isEmpty); ``` -=== "TypeScript" +=== "TS" ```typescript title="deque.ts" /* 初始化双向队列 */ @@ -814,7 +814,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linkedlist_deque.js" /* 双向链表节点 */ @@ -941,7 +941,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linkedlist_deque.ts" /* 双向链表节点 */ @@ -2413,7 +2413,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="array_deque.js" /* 基于环形数组实现的双向队列 */ @@ -2521,7 +2521,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="array_deque.ts" /* 基于环形数组实现的双向队列 */ diff --git a/chapter_stack_and_queue/queue.md b/chapter_stack_and_queue/queue.md index 79fe7a6b9..71587fb8b 100755 --- a/chapter_stack_and_queue/queue.md +++ b/chapter_stack_and_queue/queue.md @@ -136,7 +136,7 @@ comments: true isEmpty := queue.Len() == 0 ``` -=== "JavaScript" +=== "JS" ```javascript title="queue.js" /* 初始化队列 */ @@ -164,7 +164,7 @@ comments: true const empty = queue.length === 0; ``` -=== "TypeScript" +=== "TS" ```typescript title="queue.ts" /* 初始化队列 */ @@ -572,7 +572,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linkedlist_queue.js" /* 基于链表实现的队列 */ @@ -640,7 +640,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linkedlist_queue.ts" /* 基于链表实现的队列 */ @@ -1486,7 +1486,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="array_queue.js" /* 基于环形数组实现的队列 */ @@ -1555,7 +1555,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="array_queue.ts" /* 基于环形数组实现的队列 */ diff --git a/chapter_stack_and_queue/stack.md b/chapter_stack_and_queue/stack.md index 6bad46658..898b22fcd 100755 --- a/chapter_stack_and_queue/stack.md +++ b/chapter_stack_and_queue/stack.md @@ -137,7 +137,7 @@ comments: true isEmpty := len(stack) == 0 ``` -=== "JavaScript" +=== "JS" ```javascript title="stack.js" /* 初始化栈 */ @@ -164,7 +164,7 @@ comments: true const is_empty = stack.length === 0; ``` -=== "TypeScript" +=== "TS" ```typescript title="stack.ts" /* 初始化栈 */ @@ -545,7 +545,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="linkedlist_stack.js" /* 基于链表实现的栈 */ @@ -602,7 +602,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="linkedlist_stack.ts" /* 基于链表实现的栈 */ @@ -1264,7 +1264,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="array_stack.js" /* 基于数组实现的栈 */ @@ -1308,7 +1308,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="array_stack.ts" /* 基于数组实现的栈 */ diff --git a/chapter_tree/array_representation_of_tree.md b/chapter_tree/array_representation_of_tree.md index 2d7541e2f..2fd949c73 100644 --- a/chapter_tree/array_representation_of_tree.md +++ b/chapter_tree/array_representation_of_tree.md @@ -62,7 +62,7 @@ comments: true tree := []any{1, 2, 3, 4, nil, 6, 7, 8, 9, nil, nil, 12, nil, nil, 15} ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 二叉树的数组表示 */ @@ -70,7 +70,7 @@ comments: true let tree = [1, 2, 3, 4, null, 6, 7, 8, 9, null, null, 12, null, null, 15]; ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 二叉树的数组表示 */ @@ -403,16 +403,110 @@ comments: true === "Go" ```go title="array_binary_tree.go" - [class]{arrayBinaryTree}-[func]{} + /* 数组表示下的二叉树类 */ + type arrayBinaryTree struct { + tree []any + } + + /* 构造方法 */ + func newArrayBinaryTree(arr []any) *arrayBinaryTree { + return &arrayBinaryTree{ + tree: arr, + } + } + + /* 节点数量 */ + func (abt *arrayBinaryTree) size() int { + return len(abt.tree) + } + + /* 获取索引为 i 节点的值 */ + func (abt *arrayBinaryTree) val(i int) any { + // 若索引越界,则返回 null ,代表空位 + if i < 0 || i >= abt.size() { + return nil + } + return abt.tree[i] + } + + /* 获取索引为 i 节点的左子节点的索引 */ + func (abt *arrayBinaryTree) left(i int) int { + return 2*i + 1 + } + + /* 获取索引为 i 节点的右子节点的索引 */ + func (abt *arrayBinaryTree) right(i int) int { + return 2*i + 2 + } + + /* 获取索引为 i 节点的父节点的索引 */ + func (abt *arrayBinaryTree) parent(i int) int { + return (i - 1) / 2 + } + + /* 层序遍历 */ + func (abt *arrayBinaryTree) levelOrder() []any { + var res []any + // 直接遍历数组 + for i := 0; i < abt.size(); i++ { + if abt.val(i) != nil { + res = append(res, abt.val(i)) + } + } + return res + } + + /* 深度优先遍历 */ + func (abt *arrayBinaryTree) dfs(i int, order string, res *[]any) { + // 若为空位,则返回 + if abt.val(i) == nil { + return + } + // 前序遍历 + if order == "pre" { + *res = append(*res, abt.val(i)) + } + abt.dfs(abt.left(i), order, res) + // 中序遍历 + if order == "in" { + *res = append(*res, abt.val(i)) + } + abt.dfs(abt.right(i), order, res) + // 后序遍历 + if order == "post" { + *res = append(*res, abt.val(i)) + } + } + + /* 前序遍历 */ + func (abt *arrayBinaryTree) preOrder() []any { + var res []any + abt.dfs(0, "pre", &res) + return res + } + + /* 中序遍历 */ + func (abt *arrayBinaryTree) inOrder() []any { + var res []any + abt.dfs(0, "in", &res) + return res + } + + /* 后序遍历 */ + func (abt *arrayBinaryTree) postOrder() []any { + var res []any + abt.dfs(0, "post", &res) + return res + } ``` -=== "JavaScript" +=== "JS" ```javascript title="array_binary_tree.js" [class]{ArrayBinaryTree}-[func]{} ``` -=== "TypeScript" +=== "TS" ```typescript title="array_binary_tree.ts" [class]{ArrayBinaryTree}-[func]{} diff --git a/chapter_tree/avl_tree.md b/chapter_tree/avl_tree.md index 9c23e35d5..a74560a2e 100644 --- a/chapter_tree/avl_tree.md +++ b/chapter_tree/avl_tree.md @@ -79,7 +79,7 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit } ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* AVL 树节点类 */ @@ -97,7 +97,7 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit } ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* AVL 树节点类 */ @@ -271,7 +271,7 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 获取节点高度 */ @@ -288,7 +288,7 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 获取节点高度 */ @@ -473,7 +473,7 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 获取平衡因子 */ @@ -485,7 +485,7 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 获取平衡因子 */ @@ -680,7 +680,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 右旋操作 */ @@ -698,7 +698,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 右旋操作 */ @@ -917,7 +917,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 左旋操作 */ @@ -935,7 +935,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 左旋操作 */ @@ -1238,7 +1238,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 执行旋转操作,使该子树重新恢复平衡 */ @@ -1272,7 +1272,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 执行旋转操作,使该子树重新恢复平衡 */ @@ -1614,9 +1614,9 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 return NewTreeNode(val) } /* 1. 查找插入位置,并插入节点 */ - if val < node.Val { + if val < node.Val.(int) { node.Left = t.insertHelper(node.Left, val) - } else if val > node.Val { + } else if val > node.Val.(int) { node.Right = t.insertHelper(node.Right, val) } else { // 重复节点不插入,直接返回 @@ -1631,7 +1631,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 插入节点 */ @@ -1655,7 +1655,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 插入节点 */ @@ -2018,9 +2018,9 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 return nil } /* 1. 查找节点,并删除之 */ - if val < node.Val { + if val < node.Val.(int) { node.Left = t.removeHelper(node.Left, val) - } else if val > node.Val { + } else if val > node.Val.(int) { node.Right = t.removeHelper(node.Right, val) } else { if node.Left == nil || node.Right == nil { @@ -2041,7 +2041,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 for temp.Left != nil { temp = temp.Left } - node.Right = t.removeHelper(node.Right, temp.Val) + node.Right = t.removeHelper(node.Right, temp.Val.(int)) node.Val = temp.Val } } @@ -2054,7 +2054,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "JavaScript" +=== "JS" ```javascript title="avl_tree.js" /* 删除节点 */ @@ -2094,7 +2094,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉 } ``` -=== "TypeScript" +=== "TS" ```typescript title="avl_tree.ts" /* 删除节点 */ diff --git a/chapter_tree/binary_search_tree.md b/chapter_tree/binary_search_tree.md index c8fa08d00..b06a8699a 100755 --- a/chapter_tree/binary_search_tree.md +++ b/chapter_tree/binary_search_tree.md @@ -111,10 +111,10 @@ comments: true node := bst.root // 循环查找,越过叶节点后跳出 for node != nil { - if node.Val < num { + if node.Val.(int) < num { // 目标节点在 cur 的右子树中 node = node.Right - } else if node.Val > num { + } else if node.Val.(int) > num { // 目标节点在 cur 的左子树中 node = node.Left } else { @@ -127,7 +127,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search_tree.js" /* 查找节点 */ @@ -147,7 +147,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search_tree.ts" /* 查找节点 */ @@ -422,7 +422,7 @@ comments: true return } pre = cur - if cur.Val < num { + if cur.Val.(int) < num { cur = cur.Right } else { cur = cur.Left @@ -430,7 +430,7 @@ comments: true } // 插入节点 node := NewTreeNode(num) - if pre.Val < num { + if pre.Val.(int) < num { pre.Right = node } else { pre.Left = node @@ -438,7 +438,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search_tree.js" /* 插入节点 */ @@ -464,7 +464,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search_tree.ts" /* 插入节点 */ @@ -900,7 +900,7 @@ comments: true break } pre = cur - if cur.Val < num { + if cur.Val.(int) < num { // 待删除节点在右子树中 cur = cur.Right } else { @@ -940,14 +940,14 @@ comments: true tmp = tmp.Left } // 递归删除节点 tmp - bst.remove(tmp.Val) + bst.remove(tmp.Val.(int)) // 用 tmp 覆盖 cur cur.Val = tmp.Val } } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_search_tree.js" /* 删除节点 */ @@ -996,7 +996,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_search_tree.ts" /* 删除节点 */ diff --git a/chapter_tree/binary_tree.md b/chapter_tree/binary_tree.md index 4758ba217..fa24c2b40 100644 --- a/chapter_tree/binary_tree.md +++ b/chapter_tree/binary_tree.md @@ -60,7 +60,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="" /* 二叉树节点类 */ @@ -71,7 +71,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="" /* 二叉树节点类 */ @@ -265,7 +265,7 @@ comments: true n2.Right = n5 ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_tree.js" /* 初始化二叉树 */ @@ -282,7 +282,7 @@ comments: true n2.right = n5; ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_tree.ts" /* 初始化二叉树 */ @@ -431,7 +431,7 @@ comments: true n1.Left = n2 ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_tree.js" /* 插入与删除节点 */ @@ -443,7 +443,7 @@ comments: true n1.left = n2; ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_tree.ts" /* 插入与删除节点 */ diff --git a/chapter_tree/binary_tree_traversal.md b/chapter_tree/binary_tree_traversal.md index 7e1e439b7..9b8885d4e 100755 --- a/chapter_tree/binary_tree_traversal.md +++ b/chapter_tree/binary_tree_traversal.md @@ -89,12 +89,12 @@ comments: true ```go title="binary_tree_bfs.go" /* 层序遍历 */ - func levelOrder(root *TreeNode) []int { + func levelOrder(root *TreeNode) []any { // 初始化队列,加入根节点 queue := list.New() queue.PushBack(root) // 初始化一个切片,用于保存遍历序列 - nums := make([]int, 0) + nums := make([]any, 0) for queue.Len() > 0 { // 队列出队 node := queue.Remove(queue.Front()).(*TreeNode) @@ -113,7 +113,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_tree_bfs.js" /* 层序遍历 */ @@ -132,7 +132,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_tree_bfs.ts" /* 层序遍历 */ @@ -474,7 +474,7 @@ comments: true } ``` -=== "JavaScript" +=== "JS" ```javascript title="binary_tree_dfs.js" /* 前序遍历 */ @@ -505,7 +505,7 @@ comments: true } ``` -=== "TypeScript" +=== "TS" ```typescript title="binary_tree_dfs.ts" /* 前序遍历 */