File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed
solution/0800-0899/0876.Middle of the Linked List Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,31 @@ class Solution {
91
91
}
92
92
```
93
93
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
+
94
119
### ** ...**
95
120
96
121
```
Original file line number Diff line number Diff line change @@ -99,6 +99,31 @@ class Solution {
99
99
}
100
100
```
101
101
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
+
102
127
### ** ...**
103
128
104
129
```
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments