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 36a3ba1 commit 498a1d2Copy full SHA for 498a1d2
merge-two-sorted-lists/jun0811.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * function ListNode(val, next) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.next = (next===undefined ? null : next)
6
+ * }
7
+ */
8
+
9
+var mergeTwoLists = function (list1, list2) {
10
+ if (!list1) return list2;
11
+ else if (!list2) return list1;
12
13
+ if (list1.val <= list2.val) {
14
+ list1.next = mergeTwoLists(list1.next, list2);
15
+ return list1;
16
+ } else {
17
+ list2.next = mergeTwoLists(list1, list2.next);
18
+ return list2;
19
+ }
20
+};
0 commit comments