File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
typescript/src/mergeTwoSortedLists Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -9,33 +9,33 @@ export class ListNode {
9
9
}
10
10
11
11
export function mergeTwoLists (
12
- l1 : ListNode | null ,
13
- l2 : ListNode | null
12
+ list1 : ListNode | null ,
13
+ list2 : ListNode | null
14
14
) : ListNode | null {
15
15
// Create a new linked list that will contain the merged nodes
16
16
const dummyHead = new ListNode ( - 1 ) ;
17
17
let current = dummyHead ;
18
18
19
19
// We continue to merge nodes until there is at least one node in each list
20
- while ( l1 !== null && l2 !== null ) {
21
- if ( l1 . val <= l2 . val ) {
22
- current . next = l1 ;
23
- l1 = l1 . next ;
20
+ while ( list1 !== null && list2 !== null ) {
21
+ if ( list1 . val <= list2 . val ) {
22
+ current . next = list1 ;
23
+ list1 = list1 . next ;
24
24
} else {
25
- current . next = l2 ;
26
- l2 = l2 . next ;
25
+ current . next = list2 ;
26
+ list2 = list2 . next ;
27
27
}
28
28
current = current . next ;
29
29
}
30
30
31
31
// If there are nodes in the first list, add them to the end of the new list
32
- if ( l1 !== null ) {
33
- current . next = l1 ;
32
+ if ( list1 !== null ) {
33
+ current . next = list1 ;
34
34
}
35
35
36
36
// If there are nodes in the second list, add them to the end of the new list
37
- if ( l2 !== null ) {
38
- current . next = l2 ;
37
+ if ( list2 !== null ) {
38
+ current . next = list2 ;
39
39
}
40
40
41
41
return dummyHead . next ;
You can’t perform that action at this time.
0 commit comments