File tree 3 files changed +71
-0
lines changed
solution/0100-0199/0160.Intersection of Two Linked Lists
3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,31 @@ public:
200
200
}
201
201
```
202
202
203
+ ### ** TypeScript**
204
+
205
+ ``` ts
206
+ /**
207
+ * Definition for singly-linked list.
208
+ * class ListNode {
209
+ * val: number
210
+ * next: ListNode | null
211
+ * constructor(val?: number, next?: ListNode | null) {
212
+ * this.val = (val===undefined ? 0 : val)
213
+ * this.next = (next===undefined ? null : next)
214
+ * }
215
+ * }
216
+ */
217
+
218
+ function getIntersectionNode(headA : ListNode | null , headB : ListNode | null ): ListNode | null {
219
+ let p1: ListNode | null = headA ;
220
+ let p2: ListNode | null = headB ;
221
+ while (p1 != p2 ) {
222
+ p1 = p1 == null ? headB : p1 .next ;
223
+ p2 = p2 == null ? headA : p2 .next ;
224
+ }
225
+ return p1 ;
226
+ };
227
+ ```
203
228
### ** ...**
204
229
205
230
```
Original file line number Diff line number Diff line change @@ -185,6 +185,31 @@ public:
185
185
}
186
186
```
187
187
188
+ ### ** TypeScript**
189
+
190
+ ``` ts
191
+ /**
192
+ * Definition for singly-linked list.
193
+ * class ListNode {
194
+ * val: number
195
+ * next: ListNode | null
196
+ * constructor(val?: number, next?: ListNode | null) {
197
+ * this.val = (val===undefined ? 0 : val)
198
+ * this.next = (next===undefined ? null : next)
199
+ * }
200
+ * }
201
+ */
202
+
203
+ function getIntersectionNode(headA : ListNode | null , headB : ListNode | null ): ListNode | null {
204
+ let p1: ListNode | null = headA ;
205
+ let p2: ListNode | null = headB ;
206
+ while (p1 != p2 ) {
207
+ p1 = p1 == null ? headB : p1 .next ;
208
+ p2 = p2 == null ? headA : p2 .next ;
209
+ }
210
+ return p1 ;
211
+ };
212
+ ```
188
213
### ** ...**
189
214
190
215
```
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 getIntersectionNode ( headA : ListNode | null , headB : ListNode | null ) : ListNode | null {
14
+ let p1 : ListNode | null = headA ;
15
+ let p2 : ListNode | null = headB ;
16
+ while ( p1 != p2 ) {
17
+ p1 = p1 == null ? headB : p1 . next ;
18
+ p2 = p2 == null ? headA : p2 . next ;
19
+ }
20
+ return p1 ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments