We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2830df0 commit 85c5b26Copy full SHA for 85c5b26
merge-two-sorted-lists/sukyoungshin.ts
@@ -37,3 +37,18 @@ function mergeTwoLists(
37
current.next = list1 !== null ? list1 : list2;
38
return dummy.next;
39
};
40
+
41
+// 2번째 풀이 (재귀)
42
+function mergeTwoLists2(
43
+ list1: ListNode | null,
44
+ list2: ListNode | null
45
+): ListNode | null {
46
+ if (!(list1 && list2)) return list1 || list2;
47
+ if (list1.val < list2.val) {
48
+ list1.next = mergeTwoLists(list1.next, list2);
49
+ return list1;
50
+ } else {
51
+ list2.next = mergeTwoLists(list1, list2.next);
52
+ return list2;
53
+ }
54
+};
0 commit comments