From 9ec45f1d255166b35c9d04635afa009b2f792974 Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 11 Dec 2022 23:33:01 +0800 Subject: [PATCH 1/7] Add the remain TypeScript code (Chapter of Array and Linkedlist) --- .../linked_list.ts | 82 ++++++++++ .../chapter_array_and_linkedlist/list.ts | 60 +++++++ .../chapter_array_and_linkedlist/my_list.ts | 147 ++++++++++++++++++ 3 files changed, 289 insertions(+) create mode 100644 codes/typescript/chapter_array_and_linkedlist/linked_list.ts create mode 100644 codes/typescript/chapter_array_and_linkedlist/list.ts create mode 100644 codes/typescript/chapter_array_and_linkedlist/my_list.ts diff --git a/codes/typescript/chapter_array_and_linkedlist/linked_list.ts b/codes/typescript/chapter_array_and_linkedlist/linked_list.ts new file mode 100644 index 000000000..d2c339df0 --- /dev/null +++ b/codes/typescript/chapter_array_and_linkedlist/linked_list.ts @@ -0,0 +1,82 @@ +/* + * File: linked_list.ts + * Created Time: 2022-12-10 + * Author: Justin (xiefahit@gmail.com) + */ + +import ListNode from '../module/ListNode'; +import { printLinkedList } from '../module/PrintUtil'; + +function insert(n0: ListNode, P: ListNode): void { + const n1 = n0.next; + n0.next = P; + P.next = n1; +} + +function remove(n0: ListNode): void { + if (!n0.next) { + return; + } + // n0 -> P -> n1 + const P = n0.next; + const n1 = P.next; + n0.next = n1; +} + +function access(head: ListNode | null, index: number): ListNode | null { + for (let i = 0; i < index; i++) { + if (!head) { + return null; + } + head = head.next; + } + return head; +} + +function find(head: ListNode | null, target: number): number { + let index = 0; + while (head !== null) { + if (head.val === target) { + return index; + } + head = head.next; + index += 1; + } + return -1; +} + +/* Driver Code */ +/* 初始化链表 */ +// 初始化各个结点 +const n0 = new ListNode(1); +const n1 = new ListNode(3); +const n2 = new ListNode(2); +const n3 = new ListNode(5); +const n4 = new ListNode(4); +// 构建引用指向 +n0.next = n1; +n1.next = n2; +n2.next = n3; +n3.next = n4; +console.log('初始化的链表为'); +printLinkedList(n0); + +/* 插入结点 */ +insert(n0, new ListNode(0)); +console.log('插入结点后的链表为'); +printLinkedList(n0); + +/* 删除结点 */ +remove(n0); +console.log('删除结点后的链表为'); +printLinkedList(n0); + +/* 访问结点 */ +const node = access(n0, 3); +console.log(`链表中索引 3 处的结点的值 = ${node?.val}`); + +/* 查找结点 */ +const index = find(n0, 2); +console.log(`链表中值为 2 的结点的索引 = ${index}`); + +export {}; diff --git a/codes/typescript/chapter_array_and_linkedlist/list.ts b/codes/typescript/chapter_array_and_linkedlist/list.ts new file mode 100644 index 000000000..8fca2bfa1 --- /dev/null +++ b/codes/typescript/chapter_array_and_linkedlist/list.ts @@ -0,0 +1,60 @@ +/* + * File: list.ts + * Created Time: 2022-12-10 + * Author: Justin (xiefahit@gmail.com) + */ + +/* 初始化列表 */ +const list: number[] = [1, 3, 2, 5, 4]; +console.log(`列表 list = ${list}`); + +/* 访问元素 */ +const num: number = list[1]; +console.log(`访问索引 1 处的元素,得到 num = ${num}`); + +/* 更新元素 */ +list[1] = 0; +console.log(`将索引 1 处的元素更新为 0 ,得到 list = ${list}`); + +/* 清空列表 */ +list.length = 0; +console.log(`清空列表后 list = ${list}`); + +/* 尾部添加元素 */ +list.push(1); +list.push(3); +list.push(2); +list.push(5); +list.push(4); +console.log(`添加元素后 list = ${list}`); + +/* 中间插入元素 */ +list.splice(3, 0, 6); +console.log(`在索引 3 处插入数字 6 ,得到 list = ${list}`); + +/* 删除元素 */ +list.splice(3, 1); +console.log(`删除索引 3 处的元素,得到 list = ${list}`); + +/* 通过索引遍历列表 */ +let count = 0; +for (let i = 0; i < list.length; i++) { + count++; +} + +/* 直接遍历列表元素 */ +count = 0; +for (const n of list) { + count++; +} + +/* 拼接两个列表 */ +const list1: number[] = [6, 8, 7, 10, 9]; +list.push(...list1); +console.log(`将列表 list1 拼接到 list 之后,得到 list = ${list}`); + +/* 排序列表 */ +list.sort((a, b) => a - b); +console.log(`排序列表后 list = ${list}`); + +export {}; diff --git a/codes/typescript/chapter_array_and_linkedlist/my_list.ts b/codes/typescript/chapter_array_and_linkedlist/my_list.ts new file mode 100644 index 000000000..e2b6c0046 --- /dev/null +++ b/codes/typescript/chapter_array_and_linkedlist/my_list.ts @@ -0,0 +1,147 @@ +/* + * File: my_list.ts + * Created Time: 2022-12-11 + * Author: Justin (xiefahit@gmail.com) + */ + +// 列表类 +class MyList { + private nums: Array; // 数组(存储列表元素) + private _capacity: number = 10; // 列表容量 + private _size: number = 0; // 列表长度(即当前元素数量) + private extendRatio: number = 2; // 每次列表扩容的倍数 + + /* 构造函数 */ + constructor() { + this.nums = new Array(this._capacity); + } + + /* 获取列表长度(即当前元素数量)*/ + public size(): number { + return this._size; + } + + /* 获取列表容量 */ + public capacity(): number { + return this._capacity; + } + + /* 访问元素 */ + public get(index: number): number { + // 索引如果越界则抛出异常,下同 + if (index >= this._size) { + throw new Error('索引越界'); + } + return this.nums[index]; + } + + /* 更新元素 */ + public set(index: number, num: number): void { + if (index >= this._size) throw new Error('索引越界'); + this.nums[index] = num; + } + + /* 尾部添加元素 */ + public add(num: number): void { + // 如果长度等于容量,则需要扩容 + if (this._size === this._capacity) { + this.extendCapacity(); + } + // 将新元素添加到列表尾部 + this.nums[this._size] = num; + this._size++; + } + + /* 中间插入元素 */ + public insert(index: number, num: number): void { + if (index >= this._size) { + throw new Error('索引越界'); + } + // 元素数量超出容量时,触发扩容机制 + if (this._size === this._capacity) { + this.extendCapacity(); + } + // 将索引 index 以及之后的元素都向后移动一位 + for (let j = this._size - 1; j >= index; j--) { + this.nums[j + 1] = this.nums[j]; + } + // 更新元素数量 + this.nums[index] = num; + this._size++; + } + + /* 删除元素 */ + public remove(index: number): number { + if (index >= this._size) throw new Error('索引越界'); + let num = this.nums[index]; + // 将索引 index 之后的元素都向前移动一位 + for (let j = index; j < this._size - 1; j++) { + this.nums[j] = this.nums[j + 1]; + } + // 更新元素数量 + this._size--; + // 返回被删除元素 + return num; + } + + /* 列表扩容 */ + public extendCapacity(): void { + // 新建一个长度为 size 的数组,并将原数组拷贝到新数组 + this.nums = this.nums.concat( + new Array(this.capacity() * (this.extendRatio - 1)) + ); + // 更新列表容量 + this._capacity = this.nums.length; + } + + /* 将列表转换为数组 */ + public toArray(): number[] { + let size = this.size(); + // 仅转换有效长度范围内的列表元素 + let nums = new Array(size); + for (let i = 0; i < size; i++) { + nums[i] = this.get(i); + } + return nums; + } +} + +/* Driver Code */ +/* 初始化列表 */ +let list = new MyList(); +/* 尾部添加元素 */ +list.add(1); +list.add(3); +list.add(2); +list.add(5); +list.add(4); +console.log( + `列表 list = ${list.toArray()} ,容量 = ${list.capacity()} ,长度 = ${list.size()}` +); + +/* 中间插入元素 */ +list.insert(3, 6); +console.log(`在索引 3 处插入数字 6 ,得到 list = ${list.toArray()}`); + +/* 删除元素 */ +list.remove(3); +console.log(`删除索引 3 处的元素,得到 list = ${list.toArray()}`); + +/* 访问元素 */ +let num = list.get(1); +console.log(`访问索引 1 处的元素,得到 num = ${num}`); + +/* 更新元素 */ +list.set(1, 0); +console.log(`将索引 1 处的元素更新为 0 ,得到 list = ${list.toArray()}`); + +/* 测试扩容机制 */ +for (let i = 0; i < 10; i++) { + // 在 i = 5 时,列表长度将超出列表容量,此时触发扩容机制 + list.add(i); +} +console.log( + `扩容后的列表 list = ${list.toArray()} ,容量 = ${list.capacity()} ,长度 = ${list.size()}` +); + +export {}; From ad5ba2e955bccd253373d644705898332f2530de Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 11 Dec 2022 23:38:00 +0800 Subject: [PATCH 2/7] Update TypeScript style (Chapter of Array) --- .../chapter_array_and_linkedlist/array.ts | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/codes/typescript/chapter_array_and_linkedlist/array.ts b/codes/typescript/chapter_array_and_linkedlist/array.ts index 2905087ce..123cfa06a 100644 --- a/codes/typescript/chapter_array_and_linkedlist/array.ts +++ b/codes/typescript/chapter_array_and_linkedlist/array.ts @@ -7,10 +7,10 @@ /* 随机返回一个数组元素 */ function randomAccess(nums: number[]): number { // 在区间 [0, nums.length) 中随机抽取一个数字 - const random_index = Math.floor(Math.random() * nums.length) + const random_index = Math.floor(Math.random() * nums.length); // 获取并返回随机元素 - const random_num = nums[random_index] - return random_num + const random_num = nums[random_index]; + return random_num; } /* 扩展数组长度 */ @@ -18,43 +18,43 @@ function randomAccess(nums: number[]): number { // 为了方便学习,本函数将 Array 看作是长度不可变的数组 function extend(nums: number[], enlarge: number): number[] { // 初始化一个扩展长度后的数组 - const res = new Array(nums.length + enlarge).fill(0) + const res = new Array(nums.length + enlarge).fill(0); // 将原数组中的所有元素复制到新数组 - for (let i = 0; i < nums.length; i++){ - res[i] = nums[i] + for (let i = 0; i < nums.length; i++) { + res[i] = nums[i]; } // 返回扩展后的新数组 - return res + return res; } /* 在数组的索引 index 处插入元素 num */ function insert(nums: number[], num: number, index: number): void { // 把索引 index 以及之后的所有元素向后移动一位 for (let i = nums.length - 1; i >= index; i--) { - nums[i] = nums[i - 1] + nums[i] = nums[i - 1]; } // 将 num 赋给 index 处元素 - nums[index] = num + nums[index] = num; } /* 删除索引 index 处元素 */ function remove(nums: number[], index: number): void { // 把索引 index 之后的所有元素向前移动一位 for (let i = index; i < nums.length - 1; i++) { - nums[i] = nums[i + 1] + nums[i] = nums[i + 1]; } } /* 遍历数组 */ function traverse(nums: number[]): void { - let count = 0 + let count = 0; // 通过索引遍历数组 for (let i = 0; i < nums.length; i++) { - count++ + count++; } // 直接遍历数组 - for(let num of nums){ - count += 1 + for (let num of nums) { + count += 1; } } @@ -62,40 +62,40 @@ function traverse(nums: number[]): void { function find(nums: number[], target: number): number { for (let i = 0; i < nums.length; i++) { if (nums[i] === target) { - return i + return i; } } - return -1 + return -1; } /* Driver Codes*/ /* 初始化数组 */ -let arr: number[] = new Array(5).fill(0) -console.log("数组 arr =", arr) -let nums: number[] = [1, 3, 2, 5, 4] -console.log("数组 nums =", nums) +let arr: number[] = new Array(5).fill(0); +console.log('数组 arr =', arr); +let nums: number[] = [1, 3, 2, 5, 4]; +console.log('数组 nums =', nums); /* 随机访问 */ -const random_num = randomAccess(nums) -console.log("在 nums 中获取随机元素", random_num) +const random_num = randomAccess(nums); +console.log('在 nums 中获取随机元素', random_num); /* 长度扩展 */ -nums = extend(nums, 3) -console.log("将数组长度扩展至 8 ,得到 nums =", nums) +nums = extend(nums, 3); +console.log('将数组长度扩展至 8 ,得到 nums =', nums); /* 插入元素 */ -insert(nums, 6, 3) -console.log("在索引 3 处插入数字 6 ,得到 nums =", nums) +insert(nums, 6, 3); +console.log('在索引 3 处插入数字 6 ,得到 nums =', nums); /* 删除元素 */ -remove(nums, 2) -console.log("删除索引 2 处的元素,得到 nums =", nums) +remove(nums, 2); +console.log('删除索引 2 处的元素,得到 nums =', nums); /* 遍历数组 */ -traverse(nums) +traverse(nums); /* 查找元素 */ -var index: number = find(nums, 3) -console.log("在 nums 中查找元素 3 ,得到索引 =", index) +var index: number = find(nums, 3); +console.log('在 nums 中查找元素 3 ,得到索引 =', index); -export { } +export {}; From 4f1433f802845e6371655a820c593b3b5f27775e Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 11 Dec 2022 23:52:17 +0800 Subject: [PATCH 3/7] Add the module TypeScript code (Chapter of Linkedlist) --- codes/typescript/module/ListNode.ts | 9 +++++++++ codes/typescript/module/PrintUtil.ts | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 codes/typescript/module/ListNode.ts create mode 100644 codes/typescript/module/PrintUtil.ts diff --git a/codes/typescript/module/ListNode.ts b/codes/typescript/module/ListNode.ts new file mode 100644 index 000000000..543f1cf3a --- /dev/null +++ b/codes/typescript/module/ListNode.ts @@ -0,0 +1,9 @@ +// Definition for singly-linked list. +export default class ListNode { + val: number; + next: ListNode | null; + constructor(val?: number, next?: ListNode | null) { + this.val = val === undefined ? 0 : val; + this.next = next === undefined ? null : next; + } +} diff --git a/codes/typescript/module/PrintUtil.ts b/codes/typescript/module/PrintUtil.ts new file mode 100644 index 000000000..c2e3f3c75 --- /dev/null +++ b/codes/typescript/module/PrintUtil.ts @@ -0,0 +1,18 @@ +/* + * File: PrintUtil.ts + * Created Time: 2022-12-10 + * Author: Justin (xiefahit@gmail.com) + */ + +import ListNode from './ListNode'; + +function printLinkedList(head: ListNode | null): void { + const list: string[] = []; + while (head !== null) { + list.push(head.val.toString()); + head = head.next; + } + console.log(list.join(' -> ')); +} + +export { printLinkedList }; From 7c70b3c760834f4e04cd5a3cfed668a7ca7c6315 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 12 Dec 2022 00:10:40 +0800 Subject: [PATCH 4/7] Add TypeScript code to docs (Chapter of Linked_list) --- .../linked_list.md | 76 +++++++++++++++++-- 1 file changed, 70 insertions(+), 6 deletions(-) diff --git a/docs/chapter_array_and_linkedlist/linked_list.md b/docs/chapter_array_and_linkedlist/linked_list.md index d8dcce4a5..8d1d979d9 100644 --- a/docs/chapter_array_and_linkedlist/linked_list.md +++ b/docs/chapter_array_and_linkedlist/linked_list.md @@ -63,7 +63,15 @@ comments: true === "TypeScript" ```typescript title="" - + /* 链表结点结构体 */ + class ListNode { + val: number; + next: ListNode | null; + constructor(val?: number, next?: ListNode | null) { + this.val = val === undefined ? 0 : val; // 结点值 + this.next = next === undefined ? null : next; // 指向下一结点的引用 + } + } ``` === "C" @@ -152,7 +160,18 @@ comments: true === "TypeScript" ```typescript title="" - + /* 初始化链表 1 -> 3 -> 2 -> 5 -> 4 */ + // 初始化各个结点 + const n0 = new ListNode(1); + const n1 = new ListNode(3); + const n2 = new ListNode(2); + const n3 = new ListNode(5); + const n4 = new ListNode(4); + // 构建引用指向 + n0.next = n1; + n1.next = n2; + n2.next = n3; + n3.next = n4; ``` === "C" @@ -251,7 +270,22 @@ comments: true === "TypeScript" ```typescript title="" - + /* 在链表的结点 n0 之后插入结点 P */ + function insert(n0: ListNode, P: ListNode): void { + const n1 = n0.next; + n0.next = P; + P.next = n1; + } + /* 删除链表的结点 n0 之后的首个结点 */ + function remove(n0: ListNode): void { + if (!n0.next) { + return; + } + // n0 -> P -> n1 + const P = n0.next; + const n1 = P.next; + n0.next = n1; + } ``` === "C" @@ -325,7 +359,16 @@ comments: true === "TypeScript" ```typescript title="" - + /* 访问链表中索引为 index 的结点 */ + function access(head: ListNode | null, index: number): ListNode | null { + for (let i = 0; i < index; i++) { + if (!head) { + return null; + } + head = head.next; + } + return head; + } ``` === "C" @@ -407,7 +450,18 @@ comments: true === "TypeScript" ```typescript title="" - + /* 在链表中查找值为 target 的首个结点 */ + function find(head: ListNode | null, target: number): number { + let index = 0; + while (head !== null) { + if (head.val === target) { + return index; + } + head = head.next; + index += 1; + } + return -1; + } ``` === "C" @@ -480,7 +534,17 @@ comments: true === "TypeScript" ```typescript title="" - + /* 双向链表结点类 */ + class ListNode { + val: number; + next: ListNode | null; + prev: ListNode | null; + constructor(val?: number, next?: ListNode | null) { + this.val = val === undefined ? 0 : val; // 结点值 + this.next = next === undefined ? null : next; // 指向后继结点的引用 + this.prev = prev === undefined ? null : prev; // 指向前驱结点的引用 + } + } ``` === "C" From 4118e799a04c52fa1a391aa0cbcabae458afc385 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 12 Dec 2022 00:19:01 +0800 Subject: [PATCH 5/7] Update TypeScript style (Chapter of Array and Linkedlist) --- codes/typescript/chapter_array_and_linkedlist/my_list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codes/typescript/chapter_array_and_linkedlist/my_list.ts b/codes/typescript/chapter_array_and_linkedlist/my_list.ts index e2b6c0046..b2ce46840 100644 --- a/codes/typescript/chapter_array_and_linkedlist/my_list.ts +++ b/codes/typescript/chapter_array_and_linkedlist/my_list.ts @@ -4,7 +4,7 @@ * Author: Justin (xiefahit@gmail.com) */ -// 列表类 +/* 列表类简易实现 */ class MyList { private nums: Array; // 数组(存储列表元素) private _capacity: number = 10; // 列表容量 From 0b27c8947978e22d0b6c88aa66322f804a631862 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 12 Dec 2022 00:25:21 +0800 Subject: [PATCH 6/7] Add TypeScript code to docs (Chapter of List) --- docs/chapter_array_and_linkedlist/list.md | 127 +++++++++++++++++++++- 1 file changed, 124 insertions(+), 3 deletions(-) diff --git a/docs/chapter_array_and_linkedlist/list.md b/docs/chapter_array_and_linkedlist/list.md index ebff3877f..e9d02e7b7 100644 --- a/docs/chapter_array_and_linkedlist/list.md +++ b/docs/chapter_array_and_linkedlist/list.md @@ -50,7 +50,8 @@ comments: true === "TypeScript" ```typescript title="list.ts" - + /* 初始化列表 */ + const list: number[] = [1, 3, 2, 5, 4]; ``` === "C" @@ -112,7 +113,11 @@ comments: true === "TypeScript" ```typescript title="list.ts" + /* 访问元素 */ + const num: number = list[1]; + /* 更新元素 */ + list[1] = 0; ``` === "C" @@ -204,7 +209,21 @@ comments: true === "TypeScript" ```typescript title="list.ts" + /* 清空列表 */ + list.length = 0; + + /* 尾部添加元素 */ + list.push(1); + list.push(3); + list.push(2); + list.push(5); + list.push(4); + + /* 中间插入元素 */ + list.splice(3, 0, 6); + /* 删除元素 */ + list.splice(3, 1); ``` === "C" @@ -282,7 +301,17 @@ comments: true === "TypeScript" ```typescript title="list.ts" + /* 通过索引遍历列表 */ + let count = 0; + for (let i = 0; i < list.length; i++) { + count++; + } + /* 直接遍历列表元素 */ + count = 0; + for (const n of list) { + count++; + } ``` === "C" @@ -339,7 +368,9 @@ comments: true === "TypeScript" ```typescript title="list.ts" - + /* 拼接两个列表 */ + const list1: number[] = [6, 8, 7, 10, 9]; + list.push(...list1); ``` === "C" @@ -392,7 +423,8 @@ comments: true === "TypeScript" ```typescript title="list.ts" - + /* 排序列表 */ + list.sort((a, b) => a - b); // 排序后,列表元素从小到大排列 ``` === "C" @@ -687,7 +719,96 @@ comments: true === "TypeScript" ```typescript title="my_list.ts" + /* 列表类简易实现 */ + class MyList { + private nums: Array; // 数组(存储列表元素) + private _capacity: number = 10; // 列表容量 + private _size: number = 0; // 列表长度(即当前元素数量) + private extendRatio: number = 2; // 每次列表扩容的倍数 + + /* 构造函数 */ + constructor() { + this.nums = new Array(this._capacity); + } + + /* 获取列表长度(即当前元素数量)*/ + public size(): number { + return this._size; + } + + /* 获取列表容量 */ + public capacity(): number { + return this._capacity; + } + + /* 访问元素 */ + public get(index: number): number { + // 索引如果越界则抛出异常,下同 + if (index >= this._size) { + throw new Error('索引越界'); + } + return this.nums[index]; + } + /* 更新元素 */ + public set(index: number, num: number): void { + if (index >= this._size) throw new Error('索引越界'); + this.nums[index] = num; + } + + /* 尾部添加元素 */ + public add(num: number): void { + // 如果长度等于容量,则需要扩容 + if (this._size === this._capacity) { + this.extendCapacity(); + } + // 将新元素添加到列表尾部 + this.nums[this._size] = num; + this._size++; + } + + /* 中间插入元素 */ + public insert(index: number, num: number): void { + if (index >= this._size) { + throw new Error('索引越界'); + } + // 元素数量超出容量时,触发扩容机制 + if (this._size === this._capacity) { + this.extendCapacity(); + } + // 将索引 index 以及之后的元素都向后移动一位 + for (let j = this._size - 1; j >= index; j--) { + this.nums[j + 1] = this.nums[j]; + } + // 更新元素数量 + this.nums[index] = num; + this._size++; + } + + /* 删除元素 */ + public remove(index: number): number { + if (index >= this._size) throw new Error('索引越界'); + let num = this.nums[index]; + // 将索引 index 之后的元素都向前移动一位 + for (let j = index; j < this._size - 1; j++) { + this.nums[j] = this.nums[j + 1]; + } + // 更新元素数量 + this._size--; + // 返回被删除元素 + return num; + } + + /* 列表扩容 */ + public extendCapacity(): void { + // 新建一个长度为 size 的数组,并将原数组拷贝到新数组 + this.nums = this.nums.concat( + new Array(this.capacity() * (this.extendRatio - 1)) + ); + // 更新列表容量 + this._capacity = this.nums.length; + } + } ``` === "C" From 4ea5c5b9cb3a0b7e117aaab612d2fcc4e6613ab5 Mon Sep 17 00:00:00 2001 From: Yudong Jin Date: Mon, 12 Dec 2022 01:14:07 +0800 Subject: [PATCH 7/7] Update array.ts --- codes/typescript/chapter_array_and_linkedlist/array.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codes/typescript/chapter_array_and_linkedlist/array.ts b/codes/typescript/chapter_array_and_linkedlist/array.ts index 123cfa06a..e73887905 100644 --- a/codes/typescript/chapter_array_and_linkedlist/array.ts +++ b/codes/typescript/chapter_array_and_linkedlist/array.ts @@ -68,7 +68,7 @@ function find(nums: number[], target: number): number { return -1; } -/* Driver Codes*/ +/* Driver Code */ /* 初始化数组 */ let arr: number[] = new Array(5).fill(0); console.log('数组 arr =', arr);