Skip to content

Commit 3135862

Browse files
merge two sorted link list problem solved
1 parent cc238f0 commit 3135862

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

21-mergeTwoSortedList.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const mergeTwoLists = (l1, l2) => {
2+
if (!l1) return l2;
3+
if (!l2) return l1;
4+
if (l1.val < l2.val) {
5+
l1.next = mergeTwoLists(l1.next, l2);
6+
return l1;
7+
}
8+
l2.next = mergeTwoLists(l1, l2.next);
9+
return l2;
10+
};
11+
12+
console.log(mergeTwoLists([1, 2, 4], [1, 3, 4]));

0 commit comments

Comments
 (0)