Skip to content

Commit a4473c8

Browse files
committed
Refactor: 기존 노드 재활용하도록 변경
1 parent 555f558 commit a4473c8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

merge-two-sorted-lists/hwanmini.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// m: list1, n: list2
12
// 시간복잡도: O(m + n)
23
// 공간복잡도: O(m + n)
34

@@ -19,10 +20,10 @@ var mergeTwoLists = function(list1, list2) {
1920

2021
while (list1 && list2) {
2122
if (list1.val < list2.val) {
22-
res.next = new ListNode(list1.val);
23+
res.next = list1
2324
list1 = list1.next;
2425
} else {
25-
res.next = new ListNode(list2.val);
26+
res.next = list2
2627
list2 = list2.next;
2728
}
2829

0 commit comments

Comments
 (0)