Skip to content

Commit 26db402

Browse files
authored
feat: add typescript solution to lc problem: No.0876.Middle of the Linked List (doocs#450)
1 parent b4fb12e commit 26db402

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

solution/0800-0899/0876.Middle of the Linked List/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,31 @@ class Solution {
9191
}
9292
```
9393

94+
### **TypeScript**
95+
96+
```ts
97+
/**
98+
* Definition for singly-linked list.
99+
* class ListNode {
100+
* val: number
101+
* next: ListNode | null
102+
* constructor(val?: number, next?: ListNode | null) {
103+
* this.val = (val===undefined ? 0 : val)
104+
* this.next = (next===undefined ? null : next)
105+
* }
106+
* }
107+
*/
108+
109+
function middleNode(head: ListNode | null): ListNode | null {
110+
let fast = head, slow = head;
111+
while (fast != null && fast.next != null) {
112+
fast = fast.next.next;
113+
slow = slow.next;
114+
}
115+
return slow;
116+
};
117+
```
118+
94119
### **...**
95120

96121
```

solution/0800-0899/0876.Middle of the Linked List/README_EN.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ class Solution {
9999
}
100100
```
101101

102+
### **TypeScript**
103+
104+
```ts
105+
/**
106+
* Definition for singly-linked list.
107+
* class ListNode {
108+
* val: number
109+
* next: ListNode | null
110+
* constructor(val?: number, next?: ListNode | null) {
111+
* this.val = (val===undefined ? 0 : val)
112+
* this.next = (next===undefined ? null : next)
113+
* }
114+
* }
115+
*/
116+
117+
function middleNode(head: ListNode | null): ListNode | null {
118+
let fast = head, slow = head;
119+
while (fast != null && fast.next != null) {
120+
fast = fast.next.next;
121+
slow = slow.next;
122+
}
123+
return slow;
124+
};
125+
```
126+
102127
### **...**
103128

104129
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Definition for singly-linked list.
3+
* class ListNode {
4+
* val: number
5+
* next: ListNode | null
6+
* constructor(val?: number, next?: ListNode | null) {
7+
* this.val = (val===undefined ? 0 : val)
8+
* this.next = (next===undefined ? null : next)
9+
* }
10+
* }
11+
*/
12+
13+
function middleNode(head: ListNode | null): ListNode | null {
14+
let fast = head, slow = head;
15+
while (fast != null && fast.next != null) {
16+
fast = fast.next.next;
17+
slow = slow.next;
18+
}
19+
return slow;
20+
};

0 commit comments

Comments
 (0)