Skip to content

Commit 0cdbba8

Browse files
committed
refactor: feat: 21. Merge Two Sorted Lists
1 parent ca72dd4 commit 0cdbba8

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

merge-two-sorted-lists/gwbaik9717.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,12 @@ var mergeTwoLists = function (list1, list2) {
3030
current = current.next;
3131
}
3232

33-
while (list1) {
34-
current.next = new ListNode(list1.val);
35-
list1 = list1.next;
36-
current = current.next;
33+
if (list1) {
34+
current.next = list1;
3735
}
3836

39-
while (list2) {
40-
current.next = new ListNode(list2.val);
41-
list2 = list2.next;
42-
current = current.next;
37+
if (list2) {
38+
current.next = list2;
4339
}
4440

4541
return answer.next;

0 commit comments

Comments
 (0)