From 0cdbba8b7bcaf5c35b57da4d7a8ab2df517c4508 Mon Sep 17 00:00:00 2001 From: Paik Date: Thu, 2 Jan 2025 07:58:14 +0900 Subject: [PATCH] refactor: feat: 21. Merge Two Sorted Lists --- merge-two-sorted-lists/gwbaik9717.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/merge-two-sorted-lists/gwbaik9717.js b/merge-two-sorted-lists/gwbaik9717.js index 513778a83..e7d1ab988 100644 --- a/merge-two-sorted-lists/gwbaik9717.js +++ b/merge-two-sorted-lists/gwbaik9717.js @@ -30,16 +30,12 @@ var mergeTwoLists = function (list1, list2) { current = current.next; } - while (list1) { - current.next = new ListNode(list1.val); - list1 = list1.next; - current = current.next; + if (list1) { + current.next = list1; } - while (list2) { - current.next = new ListNode(list2.val); - list2 = list2.next; - current = current.next; + if (list2) { + current.next = list2; } return answer.next;