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 84283ab commit f9a83e7Copy full SHA for f9a83e7
merge-two-sorted-lists/Jeehay28.js
@@ -0,0 +1,34 @@
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
+ * @param {ListNode} list1
10
+ * @param {ListNode} list2
11
+ * @return {ListNode}
12
13
+
14
+// Time Complexity: O(m + n)
15
+// Space Complexity: O(m + n)
16
17
+var mergeTwoLists = function(list1, list2) {
18
19
20
+ if(!(list1 && list2)) {
21
+ return list1 || list2;
22
+ }
23
24
+ if(list1.val < list2.val) {
25
+ list1.next = mergeTwoLists(list1.next, list2);
26
+ return list1;
27
+ } else {
28
+ list2.next = mergeTwoLists(list1, list2.next);
29
+ return list2;
30
31
32
+};
33
34
0 commit comments