Skip to content

Commit 2147683

Browse files
committed
refactor: rename variables for solution
1 parent 2d289e3 commit 2147683

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

typescript/src/mergeTwoSortedLists/mergeTwoSortedLists.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@ export class ListNode {
99
}
1010

1111
export function mergeTwoLists(
12-
l1: ListNode | null,
13-
l2: ListNode | null
12+
list1: ListNode | null,
13+
list2: ListNode | null
1414
): ListNode | null {
1515
// Create a new linked list that will contain the merged nodes
1616
const dummyHead = new ListNode(-1);
1717
let current = dummyHead;
1818

1919
// 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;
2424
} else {
25-
current.next = l2;
26-
l2 = l2.next;
25+
current.next = list2;
26+
list2 = list2.next;
2727
}
2828
current = current.next;
2929
}
3030

3131
// 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;
3434
}
3535

3636
// 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;
3939
}
4040

4141
return dummyHead.next;

0 commit comments

Comments
 (0)