Skip to content

Commit 4e542dc

Browse files
committed
ts-4: address review comments (import, ditch extra type def)
1 parent 2b54c76 commit 4e542dc

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

typescript/Fast and Slow Pointers/linked_list_loop.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
/* Definition of ListNode:
1+
import { ListNode } from "./ds";
2+
3+
/* Definition of ListNode:
24
class ListNode {
35
val: number; next: ListNode | null;
46
constructor(val: number) {
57
this.val = val;
68
this.next = null;
79
}
8-
}
9-
*/
10+
}*/
1011

11-
function linkedListLoop(head: ListNode): boolean {
12+
function linkedListLoop(head: ListNode | null): boolean {
1213
let slow: ListNode | null = head;
1314
let fast: ListNode | null = head;
1415
// Check both 'fast' and 'fast.next' to avoid null pointer

typescript/Fast and Slow Pointers/linked_list_loop_naive.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import { ListNode } from "./ds";
2+
13
/* Definition of ListNode:
24
class ListNode {
35
val: number; next: ListNode | null;
46
constructor(val: number) {
57
this.val = val;
68
this.next = null;
79
}
8-
}
9-
*/
10+
}*/
11+
1012

11-
function linkedListLoopNaive(head: ListNode): boolean {
13+
function linkedListLoopNaive(head: ListNode | null): boolean {
1214
const visited: Set<ListNode> = new Set();
1315
let curr: ListNode | null = head;
1416
while (curr !== null) {

typescript/Fast and Slow Pointers/linked_list_midpoint.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
/* Definition of ListNode:
1+
import { ListNode } from "./ds";
2+
3+
/* Definition of ListNode:
24
class ListNode {
35
val: number; next: ListNode | null;
46
constructor(val: number) {
57
this.val = val;
68
this.next = null;
79
}
8-
}
9-
*/
10+
}*/
1011

1112

12-
function linkedListMidpoint(head: ListNode): ListNode | null {
13+
function linkedListMidpoint(head: ListNode | null): ListNode | null {
1314
let slow: ListNode | null = head;
1415
let fast: ListNode | null = head;
1516
// When the fast pointer reaches the end of the list, the slow

0 commit comments

Comments
 (0)