Skip to content

Commit 085b5ba

Browse files
committed
Runtime: 127 ms (Top 16.18%) | Memory: 43.7 MB (Top 91.75%)
1 parent 878016e commit 085b5ba

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
// Runtime: 127 ms (Top 16.18%) | Memory: 43.7 MB (Top 91.75%)
12
/**
23
* Definition for singly-linked list.
34
* function ListNode(val, next) {
4-
* this.val = (val===undefined ? 0 : val)
5-
* this.next = (next===undefined ? null : next)
5+
* this.val = (val===undefined ? 0 : val)
6+
* this.next = (next===undefined ? null : next)
67
* }
78
*/
89
/**
@@ -11,17 +12,17 @@
1112
* @return {ListNode}
1213
*/
1314
var mergeTwoLists = function(list1, list2) {
14-
15+
1516
if(!list1) return list2
1617
if(!list2) return list1
17-
18+
1819
let mergedList = new ListNode(0);
1920
let ptr = mergedList;
2021
let curr1 = list1;
2122
let curr2 = list2;
22-
23+
2324
while(curr1 && curr2){
24-
25+
2526
let newNode = new ListNode();
2627
if(!curr2 || curr1.val < curr2.val){
2728
newNode.val = curr1.val;
@@ -34,19 +35,19 @@ var mergeTwoLists = function(list1, list2) {
3435
ptr.next = newNode
3536
curr2 =curr2.next;
3637
}
37-
38+
3839
ptr = ptr.next
39-
}
40-
40+
}
41+
4142
if(curr1 !== null){
4243
ptr.next = curr1;
4344
curr1 = curr1.next;
4445
}
45-
46+
4647
if(curr2 !== null){
4748
ptr.next = curr2;
4849
curr2 = curr2.next;
4950
}
50-
51+
5152
return mergedList.next
52-
};
53+
};

0 commit comments

Comments
 (0)