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 bc77b67 commit 6d34e1aCopy full SHA for 6d34e1a
merge-two-sorted-lists/main.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
+var mergeTwoLists = function(list1, list2) {
14
+ let dummy = new ListNode();
15
+ let tail = dummy;
16
+
17
+ while (list1 !== null && list2 !== null) {
18
+ if (list1.val < list2.val) {
19
+ tail.next = list1;
20
+ list1 = list1.next
21
+ } else {
22
+ tail.next = list2;
23
+ list2 = list2.next;
24
+ }
25
+ tail = tail.next;
26
27
+ if (list1 !== null) {
28
29
+ } else if (list2 !== null) {
30
31
32
+ return dummy.next;
33
+};
34
0 commit comments